Tweaked Bridge shutdown sequence slightly
Brian Vaughn committed
May 23, 2019 at 11:46 UTC
6e8c2015fcbe53eb25715a51893f9d178c1c81a3
1 file changed
+6
-11
src/bridge.js
+6
-11
@@ -57,6 +57,12 @@ 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
+
66
// Disable the API inherited from EventEmitter that can add more listeners and send more messages.
67
this.addListener = function() {};
68
this.emit = function() {};
@@ -71,9 +77,6 @@ export default class Bridge extends EventEmitter {
77
wallUnlisten();
78
}
79
74
- // Queue the shutdown outgoing message for subscribers.
75
- this.send('shutdown');
76
-
80
// Synchronously flush all queued outgoing messages.
81
// At this step the subscribers' code may run in this call stack.
82
do {
@@ -83,17 +86,9 @@ export default class Bridge extends EventEmitter {
86
// Make sure once again that there is no dangling timer.
87
clearTimeout(this._timeoutID);
88
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
-
92
// This method is used after the bridge is marked as destroyed in shutdown sequence,
93
// so we do not bail out if the bridge marked as destroyed.
94
// It is a private method that the bridge ensures is only called at the right times.