Chris Angelico wrote:
Pike now (8.1) has a decent promise/future subsystem. It's always had great handling of multiple asynchronous operations (GUI, socket, time delay, etc) with the convenience of just returning -1 from main. Interested in people's opinions on whether it would be of value to introduce generators and (built on them) asynchronous functions.
void show_channel_info(string name) { int id = yield get_channel_id(name); mapping data = yield query_channel(id); write("Status: %s\n", data->status); mapping stream = yield get_stream_info(id); if (stream) write("%s is online, %s\n", name, stream->uptime); else write("%s is offline.\n", name);
This is WAY more readable than the equivalent with a bunch of lambda functions to capture the intermediate values.
Some "random" thoughts on this: - I've considered the readability aspect, and I fully agree that having async functions with await/yield functionality is a boost to readability; and thus it is desirable to have the ability to use it in Pike. - I have not thought through your generator description; a cursory reading seems to indicate that has some desirable features. - I see that in your example you use a "yield" keyword. Is there a reason to not use the JavaScript compatible "await" instead?