PollableDataSourcesource=newPollableDataSource();// First creates a uni that emit the polled item.// Because `poll` blocks, let's use a specific executorUni<String>pollItemFromSource=Uni.createFrom().item(source::poll).runSubscriptionOn(executor);// To get the stream of items, just repeat the uni indefinitelyMulti<String>stream=pollItemFromSource.repeat().indefinitely();Cancellablecancellable=stream.subscribe().with(item->System.out.println("Polled item: "+item));// ... later ..// when you don't want the items anymore, cancel the subscription and close the source if needed.cancellable.cancel();source.close();
You can also stop the repetition using the repeat().until() method which will continue the repetition until the given predicate returns true, and/or directly create a Multi using Multi.createBy().repeating():