Skip to content

Instantly share code, notes, and snippets.

@normanmaurer
Created June 18, 2014 08:20
Show Gist options
  • Select an option

  • Save normanmaurer/368e34696447261c98ff to your computer and use it in GitHub Desktop.

Select an option

Save normanmaurer/368e34696447261c98ff to your computer and use it in GitHub Desktop.
public class Channel {
private final Queue<Runnable> queue ...
private final ChannelExecutor executor;
....
public EventExecutor executor() {
return executor;
}
private final class ChannelExecuter implements EventExecutor, Runnable {
EventExecutor origin;
public void execute(Runnable task) {
queue.add(task);
origin.execute(this);
}
public void run() {
for (;;) {
Runnable task = queue.poll();
if (task == null) {
break;
}
task.run();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment