Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@mike-neck
Last active March 11, 2018 23:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mike-neck/2f3635a51c83892ac299f5b473847919 to your computer and use it in GitHub Desktop.
Save mike-neck/2f3635a51c83892ac299f5b473847919 to your computer and use it in GitHub Desktop.
Future -> Mono
class FutureToMono {
final ExecutorService executor = Executors.newSingleThreadExecutor();
<S> Mono<S> mono(final Future<? extends S> future) {
final MonoProcessor<S> processor = MonoProcessor.create();
executor.submit(() -> {
try {
final S stat = future.get();
processor.onNext(stat);
processor.onComplete();
} catch (InterruptedException | ExecutionException e) {
processor.onError(e);
}
});
return processor;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment