webpack / tapable

Just a little module for plugins.
MIT License
3.74k stars 395 forks source link

AsyncParallelBailHook keeps executing even after one of the tapped functions has produced a defined value #130

Open nshimiye opened 4 years ago

nshimiye commented 4 years ago

Consider this example

const { AsyncParallelBailHook } = require("tapable");

const hook = new AsyncParallelBailHook();
hook.tapPromise('A', () => new Promise(res => setTimeout(() => res(undefined), 100)));
hook.tapPromise('B', () => new Promise(res => setTimeout(() => res('B'), 5000))); // <= last to resolve
hook.tapPromise('C', () => new Promise(res => setTimeout(() => res('C'), 500)));

hook.promise().then(console.log);

Expected (hook is expected to use value from the third tap)

C

Actual (hook uses value from second tap instead)

B
nshimiye commented 4 years ago

I have proactively looked and proposed a change that would fix the above issue, if you guys think it is an issue!

sokra commented 4 years ago

This is working as expected. It's not a race, it returns the first defined value by plugin order. This way the behavior is always deterministic and independent of timing.

nshimiye commented 4 years ago

I see, thx for clarification @sokra ! Would it be possible to point me to a doc/reference that explains more about the plugin order I think that will help me figure out how to use tapable for my use-case and maybe add a test case to help others understand the expected behavior