runtimejs / runtime

[not maintained] Lightweight JavaScript library operating system for the cloud
http://runtimejs.org
Apache License 2.0
1.93k stars 128 forks source link

Asynchronous "Zones" #28

Open unixpickle opened 10 years ago

unixpickle commented 10 years ago

Dart introduced the idea of zones for catching exceptions through an asynchronous callback chain. You can read about that at https://www.dartlang.org/articles/zones/.

Runtime could employ something similar, since it employs futures and promises to wrap asynchronous callbacks.

iefserge commented 10 years ago

This looks very similar to Node domains feature (which I think adds too much complexity). With promises it's possible to .catch() all errors at the end of async chain.

piranna commented 10 years ago

This reminds me to how co, genrun and other generators-based coroutines libraries works with promises. It could be added to runtime.js, but I believe using that libraries it's enought. El 04/09/2014 17:15, "Alex Nichol" notifications@github.com escribió:

Dart introduced the idea of zones for catching exceptions through an asynchronous callback chain. You can read about that at https://www.dartlang.org/articles/zones/.

Runtime could employ something similar, since it employs futures and promises to wrap asynchronous callbacks.

— Reply to this email directly or view it on GitHub https://github.com/runtimejs/runtime/issues/28.

iefserge commented 10 years ago

Yeah, according to this benchmark https://github.com/petkaantonov/bluebird/blob/master/benchmark/stats/latest.md generators could be even faster than callbacks and consume less memory.

junosuarez commented 10 years ago

pulling in @othiym23 who has an opinion or two on the topic of domains, zones, and side-channel state in asynchronous execution stacks

unixpickle commented 10 years ago

@iefserge Zones allow more than catching exceptions on a single asynchronous callback chain. You can use zones and child-zones to catch errors on more than one callback chain, or on a part of a callback chain.

Additionally, you can use Zones to override various methods (in Dart, print is the only such method, but I think that's an under-utilization of what could be).