Skip to content

Instantly share code, notes, and snippets.

@reime005
Created December 27, 2020 21:22
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 reime005/46f081e1abc1ac39b33c5ecfbdce4f88 to your computer and use it in GitHub Desktop.
Save reime005/46f081e1abc1ac39b33c5ecfbdce4f88 to your computer and use it in GitHub Desktop.
interface ISomeEventListener {
void someEvent();
}
class SynchronousExample {
private ISomeEventListener someEventListener;
public void setSomeEventListener(ISomeEventListener someEventListener) {
this.someEventListener = someEventListener;
}
public void doSomeHeavyCalculation(final long howLongInMs) {
System.out.println("Doing some heavy work...");
// some heavy work...
try {
Thread.sleep(howLongInMs);
} catch (InterruptedException e) {
e.printStackTrace();
}
if (this.someEventListener != null) {
someEventListener.someEvent();
}
}
public static void main(String[] args) {
final SynchronousExample example = new SynchronousExample();
example.setSomeEventListener(() -> {
System.out.println("Received some event!");
});
example.doSomeHeavyCalculation(1000);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment