Skip to content

Commit 87a7602

Browse files
committed
perf: various synchronizer optimizations
1 parent 547d345 commit 87a7602

File tree

3 files changed

+18
-20
lines changed

3 files changed

+18
-20
lines changed

lib/createInlinePluginCreator.js

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,7 @@ const hasChangedDeep = require("./hasChangedDeep");
1818
function createInlinePluginCreator(packages, multiContext, synchronizer) {
1919
// Vars.
2020
const { cwd } = multiContext;
21-
const { todo, waitForAll, announceForAll, emit, getLucky } = synchronizer;
22-
23-
// Announcement of readiness for release.
24-
announceForAll("_readyToGenerateNotes");
25-
announceForAll("_readyForRelease");
21+
const { todo, waitFor, waitForAll, emit, getLucky } = synchronizer;
2622

2723
/**
2824
* Update pkg deps.
@@ -172,7 +168,7 @@ function createInlinePluginCreator(packages, multiContext, synchronizer) {
172168

173169
// Wait until the current pkg is ready to generate notes
174170
getLucky("_readyToGenerateNotes", pkg);
175-
await pkg._readyToGenerateNotes;
171+
await waitFor("_readyToGenerateNotes", pkg);
176172

177173
// Update pkg deps.
178174
updateManifestDeps(pkg, path);

lib/getSynchronizer.js

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,12 @@ const { identity } = require("lodash");
44
/**
55
* Cross-packages synchronization context.
66
* @typedef Synchronizer
7-
* @param {EventEmitter} ee Shared signal bus
7+
* @param {EventEmitter} ee Shared event emitter class.
88
* @param {Function} todo Gets the list of packages which are still todo
9-
* @params {Function} waitForAll return a promise that waits until all the packages have the same target probe value.
10-
* @params {Function} announce Attach expected state promise to target package.
11-
* @params {Function} announceForAll Attach expected state promise to all packages.
9+
* @param {Function} once Memoized event subscriber.
10+
* @param {Function} emit Memoized event emitter.
11+
* @params {Function} waitFor Function returns a promise that waits until the package has target probe value.
12+
* @params {Function} waitForAll Function returns a promise that waits until all the packages have the same target probe value.
1213
*/
1314

1415
/**
@@ -28,17 +29,22 @@ const getSynchronizer = (packages) => {
2829
evt: {},
2930
subscr: {},
3031
};
32+
3133
const emit = (probe, pkg) => {
3234
const name = getEventName(probe, pkg);
33-
3435
return store.evt[name] || (store.evt[name] = ee.emit(name));
3536
};
37+
3638
const once = (probe, pkg) => {
3739
const name = getEventName(probe, pkg);
38-
3940
return store.evt[name] || store.subscr[name] || (store.subscr[name] = ee.once(name));
4041
};
4142

43+
const waitFor = (probe, pkg) => {
44+
const name = getEventName(probe, pkg);
45+
return pkg[name] || (pkg[name] = once(probe, pkg));
46+
};
47+
4248
// Status sync point.
4349
const waitForAll = (probe, filter = identity) => {
4450
const promise = once(probe);
@@ -54,9 +60,6 @@ const getSynchronizer = (packages) => {
5460
return promise;
5561
};
5662

57-
const announce = (probe, pkg) => (pkg[probe] = once(probe, pkg));
58-
const announceForAll = (probe) => todo().forEach((p) => announce(probe, p));
59-
6063
// Only the first lucky package passes the probe.
6164
const getLucky = (probe, pkg) => {
6265
if (getLucky[probe]) {
@@ -71,8 +74,7 @@ const getSynchronizer = (packages) => {
7174
emit,
7275
once,
7376
todo,
74-
announce,
75-
announceForAll,
77+
waitFor,
7678
waitForAll,
7779
getLucky,
7880
};

lib/multiSemanticRelease.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,17 +74,17 @@ async function multiSemanticRelease(
7474

7575
// Shared signal bus.
7676
const synchronizer = getSynchronizer(packages);
77-
const { getLucky } = synchronizer;
77+
const { getLucky, waitFor } = synchronizer;
7878

7979
// Release all packages.
8080
const createInlinePlugin = createInlinePluginCreator(packages, multiContext, synchronizer);
8181
await Promise.all(
8282
packages.map(async (pkg) => {
83-
// Avoid hypothetical concurrent initialization collisions.
83+
// Avoid hypothetical concurrent initialization collisions / throttling issues.
8484
// https://github.com/dhoulb/multi-semantic-release/issues/24
8585
if (flags.sequentialInit) {
8686
getLucky("_readyForRelease", pkg);
87-
await pkg._readyForRelease;
87+
await waitFor("_readyForRelease", pkg);
8888
}
8989

9090
return releasePackage(pkg, createInlinePlugin, multiContext);

0 commit comments

Comments
 (0)