001/***************************************************
002 * Licensed under MIT No Attribution (SPDX: MIT-0) *
003 ***************************************************/
004
005package org.reactivestreams.example.unicast;
006
007import java.util.Iterator;
008import java.util.concurrent.Executor;
009
010import org.reactivestreams.Subscription;
011import org.reactivestreams.Subscriber;
012import org.reactivestreams.Publisher;
013
014public class InfiniteIncrementNumberPublisher extends AsyncIterablePublisher<Integer> {
015    public InfiniteIncrementNumberPublisher(final Executor executor) {
016        super(new Iterable<Integer>() {
017          @Override public Iterator<Integer> iterator() {
018            return new Iterator<Integer>() {
019              private int at = 0;
020              @Override public boolean hasNext() { return true; }
021              @Override public Integer next() { return at++; } // Wraps around on overflow
022              @Override public void remove() { throw new UnsupportedOperationException(); }
023            };
024          }
025        }, executor);
026    }
027}