Re: Promises (Re: New Editor's Draft of MediaStream Image Capture)

On 9 September 2014 11:02, Jan-Ivar Bruaroey <jib@mozilla.com> wrote:
> The "transition API" for UAs for the next year: [4]
> -----------------------------------------------
>
> After:
>     callback FooSuccessCallback = void (Bar bar);
>     Promise<Bar> foo (FooSuccessCallback successCallback,
> CommonErrorCallback errorCallback);

I think that this is the right approach.  More or less.  Marking the
callbacks as optional would seem to be necessary.

> Implementation is easy: we stuff any passed-in callbacks into the .then() of
> the promise before returning it.

I think that we need to be more careful about that.  Is this what you propose?

  foo: function(s, e) {
    return theRealFoo().then(s, e);
  }

The note being here that if the success callback returns void, then
that's cool.  If it returns a promise, then it chains.  Do you want
that?  or do you instead want insulation from the callback return
values?  e.g.

  foo: function(s, e) {
    return theRealFoo().then(x => { s(x); }, err => { e(err); });
  }

> [4] createOffer is a bit of a challenge with its options argument coming after the callbacks. I'm looking into that.

Does an overload work?

Received on Tuesday, 9 September 2014 22:43:34 UTC