diff --git a/lib/createInlinePluginCreator.js b/lib/createInlinePluginCreator.js index fbe4d40..1b625f9 100644 --- a/lib/createInlinePluginCreator.js +++ b/lib/createInlinePluginCreator.js @@ -18,11 +18,7 @@ const hasChangedDeep = require("./hasChangedDeep"); function createInlinePluginCreator(packages, multiContext, synchronizer) { // Vars. const { cwd } = multiContext; - const { todo, waitForAll, announceForAll, emit, getLucky } = synchronizer; - - // Announcement of readiness for release. - announceForAll("_readyToGenerateNotes"); - announceForAll("_readyForRelease"); + const { todo, waitFor, waitForAll, emit, getLucky } = synchronizer; /** * Update pkg deps. @@ -172,7 +168,7 @@ function createInlinePluginCreator(packages, multiContext, synchronizer) { // Wait until the current pkg is ready to generate notes getLucky("_readyToGenerateNotes", pkg); - await pkg._readyToGenerateNotes; + await waitFor("_readyToGenerateNotes", pkg); // Update pkg deps. updateManifestDeps(pkg, path); diff --git a/lib/getSynchronizer.js b/lib/getSynchronizer.js index f0fe85a..0dc7f7b 100644 --- a/lib/getSynchronizer.js +++ b/lib/getSynchronizer.js @@ -4,11 +4,12 @@ const { identity } = require("lodash"); /** * Cross-packages synchronization context. * @typedef Synchronizer - * @param {EventEmitter} ee Shared signal bus + * @param {EventEmitter} ee Shared event emitter class. * @param {Function} todo Gets the list of packages which are still todo - * @params {Function} waitForAll return a promise that waits until all the packages have the same target probe value. - * @params {Function} announce Attach expected state promise to target package. - * @params {Function} announceForAll Attach expected state promise to all packages. + * @param {Function} once Memoized event subscriber. + * @param {Function} emit Memoized event emitter. + * @params {Function} waitFor Function returns a promise that waits until the package has target probe value. + * @params {Function} waitForAll Function returns a promise that waits until all the packages have the same target probe value. */ /** @@ -28,17 +29,22 @@ const getSynchronizer = (packages) => { evt: {}, subscr: {}, }; + const emit = (probe, pkg) => { const name = getEventName(probe, pkg); - return store.evt[name] || (store.evt[name] = ee.emit(name)); }; + const once = (probe, pkg) => { const name = getEventName(probe, pkg); - return store.evt[name] || store.subscr[name] || (store.subscr[name] = ee.once(name)); }; + const waitFor = (probe, pkg) => { + const name = getEventName(probe, pkg); + return pkg[name] || (pkg[name] = once(probe, pkg)); + }; + // Status sync point. const waitForAll = (probe, filter = identity) => { const promise = once(probe); @@ -54,9 +60,6 @@ const getSynchronizer = (packages) => { return promise; }; - const announce = (probe, pkg) => (pkg[probe] = once(probe, pkg)); - const announceForAll = (probe) => todo().forEach((p) => announce(probe, p)); - // Only the first lucky package passes the probe. const getLucky = (probe, pkg) => { if (getLucky[probe]) { @@ -71,8 +74,7 @@ const getSynchronizer = (packages) => { emit, once, todo, - announce, - announceForAll, + waitFor, waitForAll, getLucky, }; diff --git a/lib/multiSemanticRelease.js b/lib/multiSemanticRelease.js index 00e1613..fa2516a 100644 --- a/lib/multiSemanticRelease.js +++ b/lib/multiSemanticRelease.js @@ -74,17 +74,17 @@ async function multiSemanticRelease( // Shared signal bus. const synchronizer = getSynchronizer(packages); - const { getLucky } = synchronizer; + const { getLucky, waitFor } = synchronizer; // Release all packages. const createInlinePlugin = createInlinePluginCreator(packages, multiContext, synchronizer); await Promise.all( packages.map(async (pkg) => { - // Avoid hypothetical concurrent initialization collisions. + // Avoid hypothetical concurrent initialization collisions / throttling issues. // https://github.com/dhoulb/multi-semantic-release/issues/24 if (flags.sequentialInit) { getLucky("_readyForRelease", pkg); - await pkg._readyForRelease; + await waitFor("_readyForRelease", pkg); } return releasePackage(pkg, createInlinePlugin, multiContext);