This file contains hidden or 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
| var streamA = Bacon.fromNodeCallback(client, 'get', 'foo'); | |
| var streamB = streamA.flatMap(function(foo) { | |
| return Bacon.fromNodeCallback(client, 'post', 'bar', { data: foo }); | |
| }); | |
| streamB.onError(function(err) { | |
| throw err; // error from either the GET or the POST | |
| }); |
This file contains hidden or 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
| funFact.merge(entries).onError(function(err) { | |
| throw err; // an error from the call to MongoDB or our HTTP client | |
| }); |
This file contains hidden or 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
| entries.onValue(function() { | |
| // deliberate no-op | |
| }); |
This file contains hidden or 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
| funFact.onValue(function(fact) { | |
| io.emit('message', fact); | |
| }); |
This file contains hidden or 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
| messages.onValue(function(message) { | |
| io.emit('message', '' + message.author.id + ': ' + message.txt); | |
| }); |
This file contains hidden or 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
| connections.onValue(function(socket) { | |
| socket.broadcast.emit('message', 'A new user connected, with ID: ' + socket.id); | |
| }); |
This file contains hidden or 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
| var entries = messageWindow | |
| .filter(function(acc) { | |
| return acc.length === 20; | |
| }); | |
| .flatMap(function(messages) { | |
| return Bacon.retry({ | |
| retries: 10, | |
| delay: function() { return 100; }, | |
| source: function() { | |
| return Bacon.fromNodeCallback(client, 'post', 'log', { |
This file contains hidden or 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
| var funFact = messageWindow | |
| .filter(function(acc) { | |
| return acc.length === 20; | |
| }); | |
| .flatMap(function() { | |
| return Bacon.fromNodeCallback(database.getFunFact)); | |
| }); |
This file contains hidden or 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
| var messageWindow = messages.scan([], function(acc, message) { | |
| return acc.length === 20 ? [] : acc.concat(message); | |
| }); |
This file contains hidden or 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
| var messages = connections.flatMap(function(socket) { | |
| return Bacon.fromBinder(function(sink) { | |
| socket.on('message', function(txt) { | |
| sink({ author: socket, txt: txt }); | |
| }); | |
| }); | |
| }); |