[whatwg] Proposal: createImageBitmap should return a "Promise" instead of using a callback

Ian Hickson ian at hixie.ch
Wed Jul 17 17:39:26 PDT 2013

On Thu, 18 Jul 2013, Silvia Pfeiffer wrote:
> We have the same issues with WebRTC, which already has a callback based 
> API, but there is a suggestion to replace/augment with a Promise based 
> API, so I just wanted to understand the motivation, potential 
> complications and implications.

WebRTC's constructor is synchronous, no? There are callbacks, sure; there 
are callbacks all over the place in the Web platform. Promises themselves 
use callbacks. I don't understand the relevance to createImageBitmap().

> One issue is the change in API paradigm that we use. People have got 
> used to wrapping the callback API with a Promise style API when they 
> need it. Now they have to do both: wrap the browser API for a Promise 
> style API and wrap it for a callback style API.

You don't have to wrap it for a callback style API. It _is_ a callback- 
style API. The only difference is the order of arguments.

Instead of:

   foo(success, failure);

...you write:

   foo().then(success, failure);

It's hardly cumbersome.

> It may well be that Promises are the right way to go for 
> createImageBitmap(), but we are blazing a new trail here and need to be 
> careful about the implications.

As far as I can tell, the only implications are that you can later use the 
Promise utility methods to combine things together, so you don't have to 
manage the callbacks yourself. This seems like a win.

> For example, here is an interesting discussion thread with a statement 
> that node.js originally used Promises, but moved away from them for 
> several reasons, not least because they created a 20% performance 
> degradation with v8: 
> https://github.com/gladiusjs/gladius-core/issues/127#issuecomment-5212272 

I think you're massively misreading that parenthetical.

Ian Hickson               U+1047E                )\._.,--....,'``.    fL
http://ln.hixie.ch/       U+263A                /,   _.. \   _\  ;`._ ,.
Things that are impossible just take longer.   `._.-(,_..'--(,_..'`-.;.'

More information about the whatwg mailing list