Last active
March 11, 2018 23:28
-
-
Save mike-neck/2f3635a51c83892ac299f5b473847919 to your computer and use it in GitHub Desktop.
Future -> Mono
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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