const assert = require('assert')
const BLUEBIRD = require('bluebird')
const nameAsync1 = async (name) => name
const nameAsync2 = (name) => Promise.resolve(name)
const nameAsync3 = (name) => BLUEBIRD.resolve(name)
const nameSync = (name) => name
const isPromise1 = (value) => Promise.resolve(value) === value
const isPromise2 = (value) => BLUEBIRD.resolve(value) === value
assert(isPromise1(nameAsync1('thomas')) === true, 'async function is native promise')
assert(isPromise1(nameAsync2('thomas')) === true, 'native promise resolved is native promise')
assert(isPromise1(nameAsync3('thomas')) === true, 'bluebird resolved promise is native promise')
assert(isPromise2(nameAsync1('thomas')) === true, 'async function is bluebird promise')
assert(isPromise2(nameAsync2('thomas')) === true, 'native promise resolved is bluebird promise')
assert(isPromise2(nameAsync3('thomas')) === true, 'bluebird resolved promise is bluebird promise')
// console.log(isPromise1(nameSync('thomas')))
// console.log(isPromise2(nameSync('thomas')))
// console.log(isPromise1({ then: () => {} }))
// console.log(isPromise2({ then: () => {} }))
-
-
Save sergsoares/9ae36cd7dfd15af4500708e1fef6271e to your computer and use it in GitHub Desktop.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment