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

28
LINES

< > BotCompany Repo | #1033671 // SourceTriggeredStream - a stream of objects that come in at irregular times

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

Libraryless. Click here for Pure Java version (5015L/28K).

sclass SourceTriggeredStream<A> extends Meta {
  DoneFlag ended = new(true);
  volatile A lastElement;
  new AtomicLong elementCount; 

  event newElement(A a) {
    lastElement = a;
    inc(elementCount);
  }
  
  void onNewElement(Runnable r) { onNewElement(runnableToIVF1(r)); }

  A get() { ret lastElement; }
  long elementCount() { ret elementCount!; }
  
  void end { ended.raise(); }
  bool ended() { ret ended.isUp(); }
  
  void catchError(Runnable r) {
    main catchError(ended, r);
  }
  
  // on new element, call consumer in same thread
  void directlyFeedInto(Consumer<A> consumer) {
    if (consumer != null)
      onNewElement(a -> consumer.accept(a));
  }
}

download  show line numbers  debug dex  old transpilations   

Travelled to 4 computer(s): bhatertpkbcr, ekrmjmnbrukm, mowyntqkapby, mqqgnosmbjvj

No comments. add comment

Snippet ID: #1033671
Snippet name: SourceTriggeredStream - a stream of objects that come in at irregular times
Eternal ID of this version: #1033671/16
Text MD5: f3ca9c6b871be04ad30efaeb429d73c2
Transpilation MD5: 533bae006213bc36a0eafffc077b14d6
Author: stefan
Category: javax / streams
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2021-12-28 21:29:07
Source code size: 703 bytes / 28 lines
Pitched / IR pitched: No / No
Views / Downloads: 188 / 347
Version history: 15 change(s)
Referenced in: #1034167 - Standard Classes + Interfaces (LIVE, continuation of #1003674)