001/************************************************************************ 002* Licensed under Public Domain (CC0) * 003* * 004* To the extent possible under law, the person who associated CC0 with * 005* this code has waived all copyright and related or neighboring * 006* rights to this code. * 007* * 008* You should have received a copy of the CC0 legalcode along with this * 009* work. If not, see <http://creativecommons.org/publicdomain/zero/1.0/>.* 010************************************************************************/ 011 012package org.reactivestreams.example.unicast; 013 014import java.util.Iterator; 015import java.util.concurrent.Executor; 016 017import org.reactivestreams.Subscription; 018import org.reactivestreams.Subscriber; 019import org.reactivestreams.Publisher; 020 021public class InfiniteIncrementNumberPublisher extends AsyncIterablePublisher<Integer> { 022 public InfiniteIncrementNumberPublisher(final Executor executor) { 023 super(new Iterable<Integer>() { 024 @Override public Iterator<Integer> iterator() { 025 return new Iterator<Integer>() { 026 private int at = 0; 027 @Override public boolean hasNext() { return true; } 028 @Override public Integer next() { return at++; } // Wraps around on overflow 029 @Override public void remove() { throw new UnsupportedOperationException(); } 030 }; 031 } 032 }, executor); 033 } 034}