Closed lizuncong closed 2 years ago
const { AsyncSeriesLoopHook } = require('tapable') const testhook = new AsyncSeriesLoopHook(['compilation', 'name']) let count1 = 1 let count2 = 2 let count3 = 2 testhook.tap('plugin1', (compilation, name) => { console.log('plugin1', name) compilation.sum = compilation.sum + 1 if(count1 < 1) return; count1--; return count1; }) testhook.tapPromise('plugin2', (compilation, name) => { return new Promise((resolve, reject) => { console.log('plugin2', name) setTimeout(() => { if(count2<1){ resolve() } else { resolve(count2) } count2--; }, 1000) compilation.sum = compilation.sum + 1 }) }) testhook.tapAsync('plugin3', (compilation, name,cb) => { console.log('plugin3', name) compilation.sum = compilation.sum + 4 setTimeout(() => { if(count3 < 1) { cb() } else { cb(count3); } }, 2000) return count3; }) const compilation = { sum: 0 } testhook.callAsync(compilation, 'mike', function(...args){ console.log('finish', compilation) console.log('an error', args) })
Expect:
when execute cb(count3) and the count3 is not undefined,the hook should restart from the first plugin
You might want to change cb(count3) to cb(null, count3) because the first argument is an Error argument, which cancels the execution and reports an error
cb(count3)
cb(null, count3)
Error
oh yes,thank you for your reply
Expect:
when execute cb(count3) and the count3 is not undefined,the hook should restart from the first plugin