let Order = require('packhouse/plugins/Order')
let Packhouse = require('packhouse')
let packhouse = new Packhouse()
packhouse.plugin(Order)
let group = {
tools: {
order: {
install({ store, packhouse }) {
store.order = packhouse.order()
},
handler(self, key) {
self.store
.order
.use(key, self, (error, success) => {
setTimeout(() => {
success(Date.now())
}, 1000)
})
}
}
}
}
packhouse.addGroup('demo', () => ({ data: group }))
Promise.all([
packhouse.tool('demo/order').promise('myKey'),
packhouse.tool('demo/order').promise('myKey')
]).then(([d1, d2]) => {
console.log(d1 === d2) // true
})
Promise.all([
packhouse.tool('demo/order').promise('myKey2'),
packhouse.tool('demo/order').promise('myKey3')
]).then(([d1, d2]) => {
console.log(d1 === d2) // flase
})
let order = packhouse.order()
order.use(key, { success, error }, handler)
let order = packhouse.order()
// 這是use呼叫的呼叫過程
order
.getOrCreate(key)
.buffer({
success() { ... },
error() { ... }
})
.finish(cache => cache.clear())
.action((error, success) => {
success( ... )
})