jhaynie / isometric-titanium

This is a simple prototype project / doc around a set of common and equal APIs to explore for Ti.Next.
5 stars 2 forks source link

Async vs sync #3

Open cb1kenobi opened 10 years ago

cb1kenobi commented 10 years ago

In Ti.Next, we should adopt ES6 promises and generators as first class citizens. Also, we should add support for the EventEmitter API from Node.js. With these tools, it will enabled cleaner, more robust, and more predictable APIs.

Most async operations should return either a promise or EventEmitter. We may even consider combining the two.

Many operations will likely need both sync and async APIs, such as filesystem and database functions.

For synchronizing async tasks, we should promote ES6 generators. It is a powerful way of making async code cleaner to read.

Obviously JavaScriptCore does not support the ES6 spec 100%. The spec isn't even finalized (though it is scheduled to be by mid-2015). To get around this, we can introduce the Traceur compiler (https://code.google.com/p/traceur-compiler/) into the build process. This allows our users to start using ES6 today.

yuchi commented 10 years ago

I completely agree on the generators/Promise side. If you want to keep compatibility with Node.js you must follow its ES6 support. That also means that you’ll need to shim ES5’s Function#bind :)

But leave full Node.js compatibility for another issue :)

yuchi commented 10 years ago

For completeness, async patterns are: