Event Queue
To build Non-blocking IO. It's basically a while(true)
loop keep checking if there is a response from the IO to execute the callback code
Underneath it's using kqueue()
or epoll()
which will block if there is no event. Therefore saving the computing power:
while(true) {
// check if one of the sockets in your "interest list" has ready data.
// This call will block if there is no ready data.
int amount_of_new_events = kqueue(events_to_check, new_events, ...)
// When there is ready data in at least one file descriptor, execution continues
// and all the events in `new_events` is checked.
for (int i = 0; i < amount_of_new_events; i++) {
Event event = new_events[i]
// process event
}
}