Quantcast
Channel: ClearScript
Viewing all articles
Browse latest Browse all 2297

New Post: Promises with V8

$
0
0
Hi again,

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

// run lie.js
engine.Execute(File.ReadAllText(@"C:\path\to\lie.js"));

// create a promise
engine.Execute(@"
    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 an a RequireJS example here, and one that sets up a CommonJS environment here.

Cheers!

Viewing all articles
Browse latest Browse all 2297

Latest Images

Trending Articles





Latest Images