深入 Promise
这周研究了下 Promise/A+ 规范和 Promise/A+ 的实现。写了 3 篇文章(太长,就不搬过来了):
并发布了 3 个包:
顺便擅自提出一个 Promise/A++ 规范。。其实就是在 Promise/A+ 规范上添加了 “命名Promise” 的扩展。举个栗子:
var Promise = require('named-appoint')
new Promise(function username(resolve, reject) {
setTimeout(() => {
resolve('nswbmw')
})
})
.then(function user(_, username) {
return {
name: 'nswbmw',
age: '17'
}
})
.then(function followers(_, username, user) {
return [
{
name: 'zhangsan',
age: '17'
},
{
name: 'lisi',
age: '18'
}
]
})
.then((_, user, followers, username) => {
assert.deepEqual(_, [ { name: 'zhangsan', age: '17' }, { name: 'lisi', age: '18' } ])
assert(username === 'nswbmw')
assert.deepEqual(user, { name: 'nswbmw', age: '17' })
assert.deepEqual(followers, [ { name: 'zhangsan', age: '17' }, { name: 'lisi', age: '18' } ])
})