ysmood / yaku

A lightweight promise library
https://tonicdev.com/ysmood/yaku
MIT License
290 stars 28 forks source link

Incorrect promise when calling `resolve` twice #55

Closed mariusGundersen closed 6 years ago

mariusGundersen commented 6 years ago

Here is an edge case bug that we found in our production code. In the new Promise() constructor, if the resolve callback is called twice with another promise, then the second call to resolve overwrites the first call. A simple test case:

//comment out this line to test native version
const Promise = require('yaku');

const firstValue = Promise.resolve('correct');
const testPromise = new Promise(resolve => {
  resolve(firstValue); //first resolve another promise
  resolve('wrong'); //then resolve a value
});
//this line should log `correct`, but logs `wrong`
testPromise.then(x => console.log(x));

This only seems to happen when firstValue is a promise, when it's just the string 'correct' the code works the same as the native Promise implementation.

As I said at the beginning, this is an edge case bug, as calling resolve multiple times is not good, but we had an issue with this in production (we use polyfill.io for IE11 support), so I thought I'd at least let you know of the issue.

ysmood commented 6 years ago

Sorry for taking this long to fix this bug. Busy migrating to another country these days. New version published, please check the v0.18.5.