packhouse.on('use', (event, { type, name, group }) => {
console.log(type) // tool
console.log(name) // sum
console.log(group.sign) // null *this is merger sign
console.log(group.name) // math
})
packhouse.tool('math/sum').action(...)
packhouse.on('run', (event, { id, caller, detail }) => {
let { name, args, mode, request, response, group } = detail
console.log(id) // uuid, 每次執行都會配發一個新的id
console.log(caller) // 如果該次呼叫是由另一個tool調用,可以得知是哪個id呼叫
console.log(name) // sum
console.log(args) // [10, 20]
console.log(mode) // action
console.log(request) // "[\"number\", \"number\"]"
console.log(response) // number
console.log(group.sign) // null *this is merger sign
console.log(group.name) // math
})
packhouse.tool('math/sum').action(10, 20, () => {})
packhouse.on('done', (event, { id, caller, detail }) => {
let { result, success } = detail
console.log(id) // 與執行的id相同
console.log(caller) // 如果該次呼叫是由另一個tool調用,可以得知是哪個id呼叫
console.log(success) // true
console.log(result) // 30
})
packhouse.tool('math/sum').action(10, 20, () => {})
let id = packhouse.on('run', () => {})
packhouse.off('run', id)
packhouse.on('run', event => event.off())