Skip to content

Commit 5e393f5

Browse files
committed
Revert "fix(service-broker): Awaiting ctx.emit behave differently locally and remotely issue moleculerjs#1065"
This reverts commit 0ff0f9d.
1 parent 0ff0f9d commit 5e393f5

File tree

2 files changed

+2
-33
lines changed

2 files changed

+2
-33
lines changed

src/constants.js

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,6 @@ module.exports = {
3434
FAILED_SEND_PONG_PACKET: "failedSendPongPacket",
3535
/** @type {String} Emitted when transit fails to send a HEARTBEAT packet*/
3636
FAILED_SEND_HEARTBEAT_PACKET: "failedSendHeartbeatPacket",
37-
/** @type {String} Emitted when broker fails to handler balanced event*/
38-
FAILED_HANDLER_BALANCED_EVENT: "failedHandlerBalancedEvent",
39-
/** @type {String} Emitted when broker fails to handler broadcast event*/
40-
FAILED_HANDLER_BROADCAST_EVENT: "failedHandlerBroadcastEvent",
4137
/** @type {String} Emitted when broker fails to stop all services*/
4238
FAILED_STOPPING_SERVICES: "failedServicesStop",
4339
/** @type {String} Emitted when broker fails to stop all services*/

src/service-broker.js

Lines changed: 2 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1355,7 +1355,6 @@ class ServiceBroker {
13551355
if (opts.groups && !Array.isArray(opts.groups)) opts.groups = [opts.groups];
13561356

13571357
const promises = [];
1358-
const localHandlers = [];
13591358

13601359
const ctx = this.ContextFactory.create(this, null, payload, opts);
13611360
ctx.eventName = eventName;
@@ -1385,7 +1384,7 @@ class ServiceBroker {
13851384
if (ep.id === this.nodeID) {
13861385
// Local service, call handler
13871386
const newCtx = ctx.copy(ep);
1388-
localHandlers.push(this.registry.events.callEventHandler(newCtx));
1387+
promises.push(this.registry.events.callEventHandler(newCtx));
13891388
} else {
13901389
// Remote service
13911390
const e = groupedEP[ep.id];
@@ -1407,20 +1406,6 @@ class ServiceBroker {
14071406
});
14081407
}
14091408

1410-
// invoke local handlers
1411-
setImmediate(() =>
1412-
Promise.allSettled(localHandlers).then(results => {
1413-
results
1414-
.filter(r => r.status === "rejected")
1415-
.forEach(({ reason: error }) =>
1416-
this.broadcastLocal("$broker.error", {
1417-
error,
1418-
module: "broker",
1419-
type: C.FAILED_HANDLER_BALANCED_EVENT
1420-
})
1421-
);
1422-
})
1423-
);
14241409
return this.Promise.all(promises);
14251410
} else if (this.transit) {
14261411
// Disabled balancer case
@@ -1503,19 +1488,7 @@ class ServiceBroker {
15031488
}
15041489

15051490
// Send to local services
1506-
setImmediate(() =>
1507-
this.Promise.resolve()
1508-
.then(() => this.broadcastLocal(eventName, payload, opts))
1509-
.catch(error =>
1510-
this.broadcastLocal("$broker.error", {
1511-
error,
1512-
module: "broker",
1513-
type: C.FAILED_HANDLER_BROADCAST_EVENT
1514-
})
1515-
)
1516-
// catch unresolved error
1517-
.catch(err => this.logger.error(err))
1518-
);
1491+
promises.push(this.broadcastLocal(eventName, payload, opts));
15191492

15201493
return this.Promise.all(promises);
15211494
}

0 commit comments

Comments
 (0)