Skip to content

Commit cabfa93

Browse files
jrainvilleiurimatias
authored andcommitted
fix(ipc): sends requests and events only when connected
Fixes #1063
1 parent 89e3eb6 commit cabfa93

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

src/lib/core/ipc.js

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,10 @@ class IPC {
6565
ipc.server.emit(client, 'message', message);
6666
}
6767

68-
listenTo(action, callback) {
68+
listenTo(action, callback = () => {}) {
69+
if (!this.connected) {
70+
return callback();
71+
}
6972
ipc.of['embark'].on(action, (messageString) => {
7073
callback(parse(messageString));
7174
});
@@ -75,7 +78,10 @@ class IPC {
7578
ipc.server.broadcast(action, stringify(data));
7679
}
7780

78-
once(action, cb) {
81+
once(action, cb = () => {}) {
82+
if (!this.connected) {
83+
return cb();
84+
}
7985
ipc.of['embark'].once('message', function(messageString) {
8086
const message = parse(messageString);
8187
if (message.action !== action) {
@@ -86,6 +92,10 @@ class IPC {
8692
}
8793

8894
request(action, data, cb) {
95+
if (!this.connected) {
96+
cb = cb || (() => {});
97+
return cb();
98+
}
8999
if (cb) {
90100
this.once(action, cb);
91101
}

0 commit comments

Comments
 (0)