Skip to content

Commit

Permalink
Revert "fix(service-broker): Awaiting ctx.emit behave differently loc…
Browse files Browse the repository at this point in the history
…ally and remotely issue moleculerjs#1065"

This reverts commit 0ff0f9d.
  • Loading branch information
Anton-Burdin committed Jun 1, 2022
1 parent 0ff0f9d commit 5e393f5
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 33 deletions.
4 changes: 0 additions & 4 deletions src/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,6 @@ module.exports = {
FAILED_SEND_PONG_PACKET: "failedSendPongPacket",
/** @type {String} Emitted when transit fails to send a HEARTBEAT packet*/
FAILED_SEND_HEARTBEAT_PACKET: "failedSendHeartbeatPacket",
/** @type {String} Emitted when broker fails to handler balanced event*/
FAILED_HANDLER_BALANCED_EVENT: "failedHandlerBalancedEvent",
/** @type {String} Emitted when broker fails to handler broadcast event*/
FAILED_HANDLER_BROADCAST_EVENT: "failedHandlerBroadcastEvent",
/** @type {String} Emitted when broker fails to stop all services*/
FAILED_STOPPING_SERVICES: "failedServicesStop",
/** @type {String} Emitted when broker fails to stop all services*/
Expand Down
31 changes: 2 additions & 29 deletions src/service-broker.js
Original file line number Diff line number Diff line change
Expand Up @@ -1355,7 +1355,6 @@ class ServiceBroker {
if (opts.groups && !Array.isArray(opts.groups)) opts.groups = [opts.groups];

const promises = [];
const localHandlers = [];

const ctx = this.ContextFactory.create(this, null, payload, opts);
ctx.eventName = eventName;
Expand Down Expand Up @@ -1385,7 +1384,7 @@ class ServiceBroker {
if (ep.id === this.nodeID) {
// Local service, call handler
const newCtx = ctx.copy(ep);
localHandlers.push(this.registry.events.callEventHandler(newCtx));
promises.push(this.registry.events.callEventHandler(newCtx));
} else {
// Remote service
const e = groupedEP[ep.id];
Expand All @@ -1407,20 +1406,6 @@ class ServiceBroker {
});
}

// invoke local handlers
setImmediate(() =>
Promise.allSettled(localHandlers).then(results => {
results
.filter(r => r.status === "rejected")
.forEach(({ reason: error }) =>
this.broadcastLocal("$broker.error", {
error,
module: "broker",
type: C.FAILED_HANDLER_BALANCED_EVENT
})
);
})
);
return this.Promise.all(promises);
} else if (this.transit) {
// Disabled balancer case
Expand Down Expand Up @@ -1503,19 +1488,7 @@ class ServiceBroker {
}

// Send to local services
setImmediate(() =>
this.Promise.resolve()
.then(() => this.broadcastLocal(eventName, payload, opts))
.catch(error =>
this.broadcastLocal("$broker.error", {
error,
module: "broker",
type: C.FAILED_HANDLER_BROADCAST_EVENT
})
)
// catch unresolved error
.catch(err => this.logger.error(err))
);
promises.push(this.broadcastLocal(eventName, payload, opts));

return this.Promise.all(promises);
}
Expand Down

0 comments on commit 5e393f5

Please sign in to comment.