Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save benjaminmbrown/fb0b2535ff07c16e87e4 to your computer and use it in GitHub Desktop.
Save benjaminmbrown/fb0b2535ff07c16e87e4 to your computer and use it in GitHub Desktop.
/*pseudocode for event demultplexer*/
socketA, pipeB;
watchedList.add(socketA, FOR_READ);
watchedList.add(pipeB, FOR_READ);
while(events = demultiplexer.watch(watchedList){
foreach(event in events){
/*non blocking read always returns data*/
data = event.resource.read();
if(data===RESOURCE_CLOSED){
/*stop watching if resource closed*/
demultiplexer.unwatch(event.resource);
}
else
consumeData(data);
}
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment