Skip to content

Commit

Permalink
feat(bridge): immediatly send the first message and batch the next ones
Browse files Browse the repository at this point in the history
  • Loading branch information
Guillaume Chau committed Aug 1, 2018
1 parent c09fdfb commit 39481b9
Showing 1 changed file with 12 additions and 10 deletions.
22 changes: 12 additions & 10 deletions src/bridge.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,18 +27,20 @@ export default class Bridge extends EventEmitter {

send (event, payload) {
if (this._time === null) {
this.wall.send([{ event, payload }])
this._time = Date.now()
}
this._queue.push({
event,
payload
})

const now = Date.now()
if (now - this._time > BATCH_DURATION) {
this._flush()
} else {
this._timer = setTimeout(() => this._flush(), BATCH_DURATION)
this._queue.push({
event,
payload
})

const now = Date.now()
if (now - this._time > BATCH_DURATION) {
this._flush()
} else {
this._timer = setTimeout(() => this._flush(), BATCH_DURATION)
}
}
}

Expand Down

0 comments on commit 39481b9

Please sign in to comment.