padolsey / operative

:dog2: Seamlessly create Web Workers
MIT License
655 stars 45 forks source link

Update to reflect ES6 Promise API #22

Closed Rich-Harris closed 10 years ago

Rich-Harris commented 10 years ago

I ran into some very hard-to-debug issues earlier today, which it turns out are due to a discrepancy between the native Promise API and the one that operative expects to deal with.

Essentially, the old prollyfill (the one in vendor/Promise.js) did this...

var promise = new Promise( function ( resolver ) {
  // some code happens...
  resolver.resolve(value);
});

...whereas native ES6 promises (and more up-to-date polyfills such as this one) do this:

var promise = new Promise( function ( fulfil, reject ) {
  // some code happens...
  fulfil(value);
});

The code below accommodates both scenarios - the tests all pass with both old and new polyfills.