Skip to content

Commit 0385357

Browse files
committed
waited for reduce worker p2p connection to be active before sending START_JOB
1 parent 7abdb16 commit 0385357

1 file changed

Lines changed: 16 additions & 11 deletions

File tree

src/interconnected_node/contribution/mapreduce/jobs/MapReduceMasterJob.ts

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -138,17 +138,22 @@ export default class MapReduceMasterJob implements Job {
138138
console.log('RECRUITMENT COMPLETED');
139139
}
140140
return new Promise<void>((resolve) => {
141-
masterP2PConnection.sendMessage(
142-
JSON.stringify({
143-
channel: 'START_JOB',
144-
payload: {
145-
name: 'REDUCE_WORKER',
146-
params: {
147-
reduceFunction: this.reduceFunction,
148-
},
149-
},
150-
})
151-
);
141+
const waitingForP2PConnectionToFinalize = setInterval(() => {
142+
if (masterP2PConnection.remoteDescription !== undefined) {
143+
clearInterval(waitingForP2PConnectionToFinalize);
144+
masterP2PConnection.sendMessage(
145+
JSON.stringify({
146+
channel: 'START_JOB',
147+
payload: {
148+
name: 'REDUCE_WORKER',
149+
params: {
150+
reduceFunction: this.reduceFunction,
151+
},
152+
},
153+
})
154+
);
155+
}
156+
}, 100);
152157
resolve();
153158
});
154159
}

0 commit comments

Comments
 (0)