@samitouri / QOS-React-2 / commits / d5be489d5b

Backed out Bridge shutdown refactor as it seems to have introduced bugs

Brian Vaughn committed May 29, 2019 at 14:23 UTC d5be489d5bd03d179f6df504da53c3397cf67f5a
1 file changed +11 -6
src/bridge.js
+11 -6
@@ -57,12 +57,6 @@ export default class Bridge extends EventEmitter {
57 return;
58 }
59
60 - // Queue the shutdown outgoing message for subscribers.
61 - this.send('shutdown');
62 -
63 - // Mark this bridge as destroyed, i.e. disable its public API.
64 - this._isShutdown = true;
65 -
60 // Disable the API inherited from EventEmitter that can add more listeners and send more messages.
61 this.addListener = function() {};
62 this.emit = function() {};
@@ -77,6 +71,9 @@ export default class Bridge extends EventEmitter {
71 wallUnlisten();
72 }
73
74 + // Queue the shutdown outgoing message for subscribers.
75 + this.send('shutdown');
76 +
77 // Synchronously flush all queued outgoing messages.
78 // At this step the subscribers' code may run in this call stack.
79 do {
@@ -86,9 +83,17 @@ export default class Bridge extends EventEmitter {
83 // Make sure once again that there is no dangling timer.
84 clearTimeout(this._timeoutID);
85 this._timeoutID = null;
86 +
87 + // Mark this bridge as destroyed, i.e. disable its public API.
88 + this._isShutdown = true;
89 }
90
91 _flush = () => {
92 + if (this._isShutdown) {
93 + console.warn(`Cannot flush a Bridge that has been shutdown.`);
94 + return;
95 + }
96 +
97 // This method is used after the bridge is marked as destroyed in shutdown sequence,
98 // so we do not bail out if the bridge marked as destroyed.
99 // It is a private method that the bridge ensures is only called at the right times.