Skip to content

Instantly share code, notes, and snippets.

@benjaminmbrown
Created March 15, 2016 18:35
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 benjaminmbrown/7b68f7a277d33879717a to your computer and use it in GitHub Desktop.
Save benjaminmbrown/7b68f7a277d33879717a to your computer and use it in GitHub Desktop.
#pseudo code for simple non-blocking I/O with polling loop (busy-wait)
resources = [socketA, socketB, pipeA];
while(!resources.isEmpty()){
for(i = 0; i< resources.length; i++){
resource = resources[i];
//attempt to read resource
var data = resource.read();
if(data === NO_DATA_AVAILABLE)
continue
if(DATA === RESOURCE_CLOSED)
resources.remove(i);
else
consumdeData(data)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment