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)

1  
static <A> IterableIterator<A> grabFromQueueIterator(final BlockingQueue<A> q) {
2  
  ret new IterableIterator<A>() {
3  
    A a;
4  
    bool done;
5  
    
6  
    public bool hasNext() {
7  
      getNext();
8  
      ret !done;
9  
    }
10  
    
11  
    public A next() {
12  
      getNext();
13  
      if (done) fail();
14  
      A _a = a;
15  
      a = null;
16  
      ret _a;
17  
    }
18  
    
19  
    void getNext() {
20  
      if (done || a != null) ret;
21  
      a = grabFromQueue(q);
22  
      done = a == null;
23  
    }
24  
  };
25  
}

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: 510 / 513
Referenced in: [show references]