The value is the way you can control execution: pausing, resuming, reaching in to alter state. That's useful even if everything is synchronous. Sometimes out of desire or necessity you need to do something async, and then you will always have to have some sort of typical callback/async style code...but what you can do with this is control where that code lives and express it in different ways.
In your example, have startServer start a server, then on each request create a generator, keeping a list of the active ones.
Your request handler would typically be written like this:
function requestHandler (client, request) {
sendToDatabase(request, function(data){
client.sendReply(data);
});
}
What this allows you to do is write something like this:
function requestHandler (client, request) {
data = yield sendToDatabase(request, client);
client.sendReply(data);
}
Where the callback has been moved to the sendToDataBase function. It would be something like this:
function sendToDatabase(request, client){
myDBLibrary.query(request, function(data) {
Server.clientHandlers[client].send(data);
}
}
There's a bunch of different ways you could do it, but that's the general idea.
In your example, have startServer start a server, then on each request create a generator, keeping a list of the active ones.
Your request handler would typically be written like this:
What this allows you to do is write something like this: Where the callback has been moved to the sendToDataBase function. It would be something like this: There's a bunch of different ways you could do it, but that's the general idea.