This project has moved and is read-only. For the latest updates, please go here.

Promises with V8

Aug 13, 2014 at 10:24 PM
Edited Aug 13, 2014 at 10:25 PM
Is there support for Promises/A like promises with Clearscript V8? (Chrome 32 has native support for promises, so I am assuming V8 does as well since chrome uses V8)

Or if not, how does one use When.js or Task.js with Clearscript V8.

Aug 14, 2014 at 2:53 PM
Edited Aug 14, 2014 at 2:54 PM
Hi Shrainik,

ClearScript's current release has been tested with V8 3.24, which doesn't have built-in promises enabled by default. Unfortunately neither does V8 3.26, which is the target for ClearScript's next release.

Until built-in promises are enabled in ClearScript, you should be able to use one of the available external implementations, perhaps with some modifications. Another possibility might be to leverage ClearScript's environment and implement the promise API pattern on top of .NET Tasks.

Good luck!
Aug 14, 2014 at 7:46 PM
Edited Aug 14, 2014 at 7:46 PM
The external implementation which I could find being closest to Promises/A proposal was task.js. But that relies on generators, which is again something which V8 3.24 doesn't support.

Any other suggestions would be really helpful.

Also, are there any recommended guidelines for loading external modules?

Aug 15, 2014 at 3:44 AM
Edited Aug 15, 2014 at 9:01 PM
Hi again,

Lie is one possibility. Using it with ClearScript requires no modifications and only minor setup:
// setup
    self = this;
    setTimeout = function (func, delay) {
        // add code here

// run lie.js

// create a promise
    x = new Promise(function (resolve, reject) {
        // add code here
You just need to provide a setTimeout() function that works with your application's async model.

As for modules, ClearScript doesn't define or depend on any particular solution, as it provides only low-level script engine integration. With .NET facilities at its disposal, the host should be able to implement or reuse whatever packaging scheme it requires.

However, because existing implementations often assume a browser or Node.js environment, the host may have to provide a bit of plumbing. You can find a RequireJS example here, and one that sets up a CommonJS environment here.

Aug 15, 2014 at 5:30 PM
Thanks! Let me try this out.