Not logged in.  Login/Logout/Register | List snippets | | Create snippet | Upload image | Upload data

32
LINES

< > BotCompany Repo | #1030046 // ReliableSingleThread_Multi - handle coalescing updates for multiple objects (all executed in a single thread)

JavaX fragment (include) [tags: use-pretranspiled]

Libraryless. Click here for Pure Java version (4083L/24K).

1  
sclass ReliableSingleThread_Multi<A> {
2  
  IVF1<A> processObject;
3  
  int delay; // delay before changes are processed
4  
  
5  
  *(IVF1<A> *processObject) {}
6  
  *(int *delay, IVF1<A> *processObject) {}
7  
  *(int *delay, IVF1<A> *processObject, F0<AutoCloseable> enter) { setEnter(enter); }
8  
  
9  
  // internal
10  
  Set<A> changedObjects = synchroSet();
11  
  ReliableSingleThread rst = new(r process);
12  
13  
  // notify of change in object
14  
  void add(A a) {
15  
    if (changedObjects.add(a))
16  
      rst.trigger();
17  
  }
18  
  
19  
  void addAll(Iterable<A> l) {
20  
    fOr ping (A a : l) add(a);
21  
  }
22  
  
23  
  private void process {
24  
    sleep(delay);
25  
    for ping (A object : syncCloneAndClearList(changedObjects))
26  
      pcallF(processObject, object);
27  
  }
28  
  
29  
  void setEnter(F0<AutoCloseable> enter) {
30  
    rst.enter = enter;
31  
  }
32  
}

Author comment

Began life as a copy of #1017613

download  show line numbers  debug dex  old transpilations   

Travelled to 4 computer(s): bhatertpkbcr, mqqgnosmbjvj, pyentgdyhuwx, vouqrxazstgt

No comments. add comment

Snippet ID: #1030046
Snippet name: ReliableSingleThread_Multi - handle coalescing updates for multiple objects (all executed in a single thread)
Eternal ID of this version: #1030046/16
Text MD5: 46746722114eaa9c82df593a2f6984f8
Transpilation MD5: af976b88e3ea8d2bdb956cac7882ef90
Author: stefan
Category: javax / a.i.
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2021-06-29 02:47:02
Source code size: 812 bytes / 32 lines
Pitched / IR pitched: No / No
Views / Downloads: 367 / 667
Version history: 15 change(s)
Referenced in: [show references]