Skip to content

Instantly share code, notes, and snippets.

@eleinadani
Last active February 7, 2019 21:15
Show Gist options
  • Save eleinadani/f05f6e3f72ca7ab751b12898bca98b51 to your computer and use it in GitHub Desktop.
Save eleinadani/f05f6e3f72ca7ab751b12898bca98b51 to your computer and use it in GitHub Desktop.
public class AwesomeClass {
// a concurrent queue shared with Node
private final Queue<Object> queue;
public AwesomeClass(Queue<Object> queue) {
this.queue = queue;
}
public void start() {
Thread thread = new Thread(new Runnable() {
@Override
public void run() {
// simulate asynchronous events, e.g., an HTTP request or a long computation
while (serverIsOnline) {
Object data = doSomeComputation();
// awake the Node.js worker, which will notify the main Node.js' loop
queue.offer(data);
}
}
});
thread.start();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment