public ReactiveSeq<Seq<T>> streamGroupedBySizeAndTime(int size, long time, TimeUnit t){ long toRun = t.toNanos(time); return streamBatch(new Subscription(), source->{ return ()->{ List<T> result = new ArrayList<>(); long start = System.nanoTime(); try { while (result.size() < size && checkTime(System.nanoTime(), start, toRun)) { try { T next = source.apply(100l, TimeUnit.MICROSECONDS); if (next != null) { result.add(next); } } catch (Queue.QueueTimeoutException e) { } } }catch(Queue.ClosedQueueException e){ if(result.size()>0) { List list = new ArrayList<>(); list.add(result); throw new ClosedQueueException(list); } } return result; }; }).filter(l->l.size()>0) .map(Seq::fromIterable); }
public ReactiveSeq<Seq<T>> streamGroupedBySizeAndTime(int size, long time, TimeUnit t){ long toRun = t.toNanos(time); return streamBatch(new Subscription(), source->{ return ()->{ List<T> result = new ArrayList<>(); long start = System.nanoTime(); try { while (result.size() < size && checkTime(System.nanoTime(), start, toRun)) { try { T next = source.apply(100l, TimeUnit.MICROSECONDS); if (next != null) { result.add(next); } } catch (Queue.QueueTimeoutException e) { } } }catch(Queue.ClosedQueueException e){ if(result.size()>0) { List list = new ArrayList<>(); list.add(result); throw new ClosedQueueException(list); } } return result; }; }).filter(l->l.size()>0) .map(Seq::fromIterable); }