/* MIT License http://www.opensource.org/licenses/mit-license.php Author Tobias Koppers @sokra */ "use strict"; const Hook = require("./Hook"); const HookCodeFactory = require("./HookCodeFactory"); /** @typedef {import("./Hook").EXPECTED_ANY} EXPECTED_ANY */ /** @typedef {import("./Hook").EXPECTED_FUNCTION} EXPECTED_FUNCTION */ /** @typedef {import("./Hook").CompileOptions} CompileOptions */ /** @typedef {import("./Hook").UnsetAdditionalOptions} UnsetAdditionalOptions */ /** @typedef {import("./HookCodeFactory").ContentOptions} ContentOptions */ /** * @template {EXPECTED_ANY[]} T * @typedef {import("./Hook").ArgumentNames} ArgumentNames */ /** * @template T * @typedef {import("./Hook").AsArray} AsArray */ /** * Mirror of the `AsyncParallelHook` class declared in `tapable.d.ts` for use * as the factory function's return type, so `new AsyncParallelHook(...)` * resolves to the specific subclass type instead of the generic `Hook`. * @template T * @template [AdditionalOptions=UnsetAdditionalOptions] * @typedef {import("../tapable").AsyncParallelHook} AsyncParallelHookType */ class AsyncParallelHookCodeFactory extends HookCodeFactory { /** * @param {ContentOptions} options content generation options * @returns {string} generated body code */ content({ onError, onDone }) { return this.callTapsParallel({ onError: (i, err, done, doneBreak) => onError(err) + doneBreak(true), onDone }); } } const factory = new AsyncParallelHookCodeFactory(); /** * @this {Hook} * @param {CompileOptions} options compile options * @returns {EXPECTED_FUNCTION} the compiled call function */ function COMPILE(options) { factory.setup(this, options); return factory.create(options); } /** * @constructor * @template T * @template [AdditionalOptions=UnsetAdditionalOptions] * @param {ArgumentNames>=} args argument names of the hook * @param {string=} name name of the hook * @returns {AsyncParallelHookType} a new AsyncParallelHook instance */ function AsyncParallelHook( args = /** @type {ArgumentNames>} */ (/** @type {unknown} */ ([])), name = undefined ) { const hook = new Hook(args, name); hook.constructor = AsyncParallelHook; hook.compile = COMPILE; // @ts-expect-error for performance reasons hook._call = undefined; hook.call = undefined; return /** @type {AsyncParallelHookType} */ ( /** @type {unknown} */ (hook) ); } /** @type {EXPECTED_ANY} */ AsyncParallelHook.prototype = null; module.exports = AsyncParallelHook;