Skip to content

Commit 39481b9

Browse files
author
Guillaume Chau
committed
feat(bridge): immediatly send the first message and batch the next ones
1 parent c09fdfb commit 39481b9

File tree

1 file changed

+12
-10
lines changed

1 file changed

+12
-10
lines changed

src/bridge.js

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -27,18 +27,20 @@ export default class Bridge extends EventEmitter {
2727

2828
send (event, payload) {
2929
if (this._time === null) {
30+
this.wall.send([{ event, payload }])
3031
this._time = Date.now()
31-
}
32-
this._queue.push({
33-
event,
34-
payload
35-
})
36-
37-
const now = Date.now()
38-
if (now - this._time > BATCH_DURATION) {
39-
this._flush()
4032
} else {
41-
this._timer = setTimeout(() => this._flush(), BATCH_DURATION)
33+
this._queue.push({
34+
event,
35+
payload
36+
})
37+
38+
const now = Date.now()
39+
if (now - this._time > BATCH_DURATION) {
40+
this._flush()
41+
} else {
42+
this._timer = setTimeout(() => this._flush(), BATCH_DURATION)
43+
}
4244
}
4345
}
4446

0 commit comments

Comments
 (0)