GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — cluster: use Map to track callbacks · nodejs/node@22f51a6

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • lib/internal/cluster
    • utils.js
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎lib/internal/cluster/utils.js‎

Copy file name to clipboardExpand all lines: lib/internal/cluster/utils.js
+9-5Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ module.exports = {
77
handles: {} // Used in tests.
88
};
99

10-
const callbacks = {};
10+
const callbacks = new Map();
1111
var seq = 0;
1212

1313
function sendHelper(proc, message, handle, cb) {
@@ -18,7 +18,7 @@ function sendHelper(proc, message, handle, cb) {
1818
message = util._extend({ cmd: 'NODE_CLUSTER' }, message);
1919

2020
if (typeof cb === 'function')
21-
callbacks[seq] = cb;
21+
callbacks.set(seq, cb);
2222

2323
message.seq = seq;
2424
seq += 1;
@@ -34,9 +34,13 @@ function internal(worker, cb) {
3434

3535
var fn = cb;
3636

37-
if (message.ack !== undefined && callbacks[message.ack] !== undefined) {
38-
fn = callbacks[message.ack];
39-
delete callbacks[message.ack];
37+
if (message.ack !== undefined) {
38+
const callback = callbacks.get(message.ack);
39+
40+
if (callback !== undefined) {
41+
fn = callback;
42+
callbacks.delete(message.ack);
43+
}
4044
}
4145

4246
fn.apply(worker, arguments);

0 commit comments

Comments
0 (0)
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.