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

25
LINES

< > BotCompany Repo | #1005525 // grabFromQueueIterator - wrap grabFromQueue in an IterableIterator

JavaX fragment (include)

static <A> IterableIterator<A> grabFromQueueIterator(final BlockingQueue<A> q) {
  ret new IterableIterator<A>() {
    A a;
    bool done;
    
    public bool hasNext() {
      getNext();
      ret !done;
    }
    
    public A next() {
      getNext();
      if (done) fail();
      A _a = a;
      a = null;
      ret _a;
    }
    
    void getNext() {
      if (done || a != null) ret;
      a = grabFromQueue(q);
      done = a == null;
    }
  };
}

Author comment

Began life as a copy of #1004547

download  show line numbers  debug dex  old transpilations   

Travelled to 14 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, ddnzoavkxhuk, gwrvuhgaqvyk, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt

No comments. add comment

Snippet ID: #1005525
Snippet name: grabFromQueueIterator - wrap grabFromQueue in an IterableIterator
Eternal ID of this version: #1005525/1
Text MD5: ab118a6f9d780d9181c15193bdc044b9
Author: stefan
Category: javax
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2016-11-25 16:12:30
Source code size: 480 bytes / 25 lines
Pitched / IR pitched: No / No
Views / Downloads: 513 / 516
Referenced in: [show references]