Edge JsRT: Promises

One of the major additions to the ES6 API surface was Promises. I’m not going to go into the deep nitty-gritty about Promises (you can find more here), but in a nutshell a Promise represents an asynchronous operation. So you can call an API that does something long running, and it can immediately return to you a Promise that represents the result of that action in the future. You then can say “When this promise is fulfilled (i.e. the operation is completed), please call me back and I’ll do something with the result.”

Mostly, hosts don’t have anything special to do with Promises except for that last bit–the “please call me back” part. When the long-running operation completes and it notifies the Promise object that it has been fulfilled, there has to be a way for the Promise to tell the host, “OK, now you need to run this bit of code (i.e. the part that wants to be called back when the Promise is fulfilled.)”. Hosts can now set this up by calling JsSetPromiseContinuationCallback. It allows the host to provide a callback to Chakra that Chakra can call when a Promise completion callback needs to be queued up. The parameter will be a JS function that will need to be called whenever the host has some available time (i.e. when something else isn’t running in the associated Chakra context).

You should also follow me on Twitter here.

One thought on “Edge JsRT: Promises

  1. Pingback: Edge JsRT: Universal Windows Platform | Panopticon Central

Leave a Reply

Your email address will not be published. Required fields are marked *