Skip to content

Instantly share code, notes, and snippets.

@gladimdim
Created April 11, 2019 09:41
Show Gist options
  • Save gladimdim/f5043fa120d3b7b8b6d8e85c94ab6753 to your computer and use it in GitHub Desktop.
Save gladimdim/f5043fa120d3b7b8b6d8e85c94ab6753 to your computer and use it in GitHub Desktop.
dispatchCall(Call call) {
Responder processor;
for (var i = 0; i < allProcessors.length; i++) {
try {
processor = allProcessors[i].firstWhere((Responder p) => !p.isBusy());
} catch (e) {
print('Switching to next level');
continue;
}
if (processor != null) {
break;
}
}
// if all processors are busy we add call to queue
if (processor == null) {
queueCalls.add(call);
} else {
processor.respondToCall(call);
// we add a callback listener to now when the call is ended to
// check the queue and do other stuff in CallCenter
call.addEndCallback(callEnded);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment