Created
March 12, 2020 03:12
-
-
Save SDiamante13/5c41a4fd01b878a9afedc91fb4ba00c8 to your computer and use it in GitHub Desktop.
Classes that use asynchronous method calls
This file contains hidden or 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 MyService { | |
| private final Client client; | |
| public MyService(Client client) { | |
| this.client = client; | |
| } | |
| StringBuilder getData() { | |
| StringBuilder data = new StringBuilder(); | |
| client.processData(() -> { | |
| try { | |
| Thread.sleep(3000); | |
| } catch (InterruptedException e) { | |
| e.printStackTrace(); | |
| } | |
| data.append("Here's your data!"); | |
| }); | |
| return data; | |
| } | |
| } | |
| @Component | |
| class Client { | |
| public void processData(Runnable runnable) { | |
| runnable.run(); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment