This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const pendingItems = new Rx.Subject(); | |
const maxRetries = 3; | |
const queue = (item) => { | |
let workingItem = item; | |
if (!workingItem.sync) { | |
workingItem = { | |
sync: { counter: 0 }, | |
item, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
pendingItems | |
.map(item => Rx.Observable.of(item).delay(item.sync.counter > 0 ? delayBetweenRetries : 0)) | |
.mergeAll() | |
.subscribe((itemWithMetaData) => { | |
api.syncEvent(itemWithMetaData.item) | |
.then((result) => { | |
console.log('successfully synced a mouse event'); | |
}) | |
.catch((reason) => { | |
console.error('got an error while trying to sync an event, going to try again'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const pendingItems = new Rx.Subject(); | |
const failedItems = new Rx.Subject(); | |
const syncedItems = new Rx.Subject(); | |
const maxRetries = 3; | |
const queue = (item) => { | |
let workingItem = item; | |
if (!workingItem.sync) { | |
workingItem = { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const sync = createSync({ | |
maxRetries: 3, | |
delayBetweenRetries: 2000, | |
syncAction: api.syncEvent, | |
}); | |
// success | |
sync.syncedItems.subscribe(x => console.log(x.item)); | |
// failure |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const sync = createSync({ | |
maxRetries: 3, | |
delayBetweenRetries: 2000, | |
syncAction: api.syncEvent, | |
}); | |
// success | |
sync.syncedItems.subscribe(x => console.log(x.item)); | |
// failure |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const io = require('socket.io')(); | |
const port = 8000; | |
io.on('connection', (client) => { | |
client.on('subscribeToTimer', (interval) => { | |
console.log('client is subscribing to timer with interval ', interval); | |
setInterval(() => { | |
client.emit('timer', new Date()); | |
}, interval); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const io = require('socket.io')(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
io.on('connection', (client) => { | |
// here you can start emitting events to the client | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const port = 8000; | |
io.listen(port); | |
console.log('listening on port ', port); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
io.on('connection', (client) => { | |
client.on('subscribeToTimer', (interval) => { | |
console.log('client is subscribing to timer with interval ', interval); | |
}); | |
}); |