Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
app.use(
serveStatic(root, {
index: ['index.html', 'index.htm']
})
);
// Create server
const server = http.createServer(app);
server.listen(3001, () => {
console.log(chalk.yellow('Example server start @ 3001'));
open('http://localhost:3001');
});
let watcher;
// Start the watch files with Bacon wrapper
const streamWatcher = bacon.fromBinder(sink => {
watcher = chokidar.watch(root, { ignored: /(^|[\/\\])\../ });
watcher.on('all', (event, path) => {
sink({ event: event, path: path });
return () => {
watcher.unwatch(root);
};
});
});
let files = [];
streamWatcher
.skipDuplicates(_.isEqual)
.map('.path')
.doAction(f => files.push(f))
.debounce(300)
.onValue(files => {
if (files.length) {
function openWebSocket ({ url, authMessage, startPing, stopPing }) {
return Bacon.fromBinder((sink) => {
const ws = new WebSocket(url);
ws.on('open', () => {
Logger.debug('WebSocket opened successfully: ' + url);
// TODO, we're investigating sending a success/error response from the server side through the WS
ws.send(authMessage);
startPing((p) => ws.send(p));
});
ws.on('message', (data) => sink(data));
ws.on('close', () => {
Logger.debug('WebSocket closed.');
stopPing();
sink(new Bacon.End());
fn: function(red) {
var done = 0;
var run1, run2;
var stream1 = Bacon.fromBinder(function(e){
run1 = e;
})
var stream2 = Bacon.fromBinder(function(e){
run2 = e;
});
stream1.sampledBy(stream2, function(a,b){
return a > b ? a : b
}).onValue(function(e){
done++
if(done>1000){
red.resolve();
}
})
while(done<=1000){
fn: function(red) {
var done = 0;
var run1, run2;
var stream1 = Bacon.fromBinder(function(e){
run1 = e;
})
var stream2 = Bacon.fromBinder(function(e){
run2 = e;
});
stream1.sampledBy(stream2, function(a,b){
return a > b ? a : b
}).onValue(function(e){
done++
if(done>1000){
red.resolve();
}
})
while(done<=1000){
run1(Math.random()*10);
run2(Math.random()*10);
}
function fakeLogApi() {
var WebSocketServer = require("ws").Server;
return Bacon.fromBinder(function(sink) {
var authorized = false;
var closedAppCount = 0;
var responseLog = JSON.stringify({
"_index": "customers",
"_type": "syslog",
"_id": "uvbsPlTWSpaC8WiQjLswPw",
"_score": null,
"_source": {
"message": "Received signal 15; terminating.",
"@version": "1",
"@timestamp": "2015-01-06T18:10:37.606Z",
"host": "62411bb9-40ee-4cf0-aab8-a82e21d057e4",
"type": "syslog",
"tags": ["tcp", "syslog", "customers"],
"syslog_pri": "38",
fromESObservable: observable =>
Bacon.fromBinder(sink => {
const { unsubscribe } = observable.subscribe({
next: val => sink(new Bacon.Next(val)),
error: err => sink(new Bacon.Error(err)),
complete: () => sink(new Bacon.End()),
})
return unsubscribe
}),
toESObservable: stream => ({
export function createStream (obj: Object, funcName: string, ...args: Array): Bacon.Stream {
return Bacon.fromBinder(sink => {
args.push(sink)
const disposable = obj[funcName].apply(obj, args)
return () => disposable.dispose()
})
}
export function connect(WS, location, path) {
return Bacon.fromBinder(function(sink) {
const protocol = location.protocol === "https:" ? "wss:" : "ws:";
const socket = new WS(protocol + "//" + location.host + path);
socket.onmessage = function(message) {
try {
const data = JSON.parse(message.data);
sink(data.type === "error" ? new Bacon.Error(data) : data);
} catch (e) {
sink(new Bacon.Error(e));
}
};
socket.onerror = function() {
sink(new Bacon.End());
socket.close();
};