Last active
December 5, 2017 17:14
-
-
Save olbpetersson/2e693f66194d55e99e6ff62a4f5e7f40 to your computer and use it in GitHub Desktop.
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
/* Synchronously prints | |
main | |
Current thread: main | |
hello, world! | |
Current thread: main | |
hello | |
Current thread: main | |
world | |
In about 15 seconds */ | |
@Override | |
public void run(String... args) throws Exception { | |
// Check Hooks. | |
System.out.println(Thread.currentThread().getName()); | |
Mono<String> helloWorld = Mono.just("hello, world!"); | |
helloWorld.subscribe((x) -> { | |
this.printStringWithTimeout(x, 5000); | |
}); | |
Flux<String> fluxHelloWorld = Flux.just("hello", "world"); | |
fluxHelloWorld.subscribe((x) -> { | |
this.printStringWithTimeout(x, 5000); | |
}); | |
} | |
public void printStringWithTimeout(String string, long timeoutMs) { | |
try { | |
Thread.sleep(5000); | |
} catch (InterruptedException e) { | |
e.printStackTrace(); | |
} | |
System.out.println("Current thread: " + Thread.currentThread().getName()); | |
System.out.println(string); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment