Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
it('should optimize the connection handler', () => {
// This will fail if tests are run without --allow-natives-syntax
assert(v8.isNative())
// This quacks close enough to a WebSocket
const socket = new EventEmitter();
socket.readyState = 1;
socket.upgradeReq = {
headers: {},
connection: {
remoteAddress: '127.0.0.1'
}
};
const observables = {
foo() { return Rx.Observable.of(1,2,3); }
};
const subject = new Rx.Subject();
function doCall() {
// We just want this to run, we don't care what it actually does in this
// specific test.
module.exports = lnPath => {
const ln = LightningClient(lnPath)
, em = new EventEmitter
// Continuously long-poll invoice payment updates
async function waitany(last_index) {
try {
const inv = await ln.waitanyinvoice(last_index)
em.emit('payment', inv)
waitany(inv.pay_index)
} catch (err) {
console.error(err.stack || err.toString())
setTimeout(_ => waitany(last_index), 10000)
}
}
// Start waitany() with the last known invoice
ln.client.on('connect', _ =>
ln.listinvoices()
function createPadHandler( gamePad ){
const events = new Emitter();
let lastButtons = cloneButtons( gamePad.buttons );
function update(){
const buttons = gamePad.buttons;
// compare
buttons.forEach( ( button, index )=>{
const lastButton = lastButtons[ index ];
// console.log( button.pressed, lastButton.pressed );
if( button.pressed !== lastButton.pressed ){
if( button.pressed ){
events.emit( 'buttonPressed', index, button.value );
events.emit( 'button'+index+'Pressed', button.value );
import EventEmitter from 'events';
const EventBridge = new EventEmitter();
EventBridge.setMaxListeners(30);
// An internal hook for the native side, from which we propagate events through
// the EventEmitter interface.
__BlueprintNative__.dispatchEvent = function dispatchEvent(eventType, ...args) {
EventBridge.emit(eventType, ...args);
}
export default EventBridge;
function createObjectEmitter(stream) {
const streamSplitter = new StreamSplitter('\n'),
emitter = new EventEmitter();
stream = stream.pipe(streamSplitter);
stream.encoding = 'utf8';
stream.on('token', function (token) {
let obj;
try {
obj = JSON.parse(token);
emitter.emit('data', obj);
} catch (ex) {
log('error', require('util').inspect(token), ex);
// we don't have enough data yet, maybe?
}
});
stream.on('error', error => emitter.emit('error', error));
* @prop {string} pathname
* @prop {string} href
* @prop {string} title
* @prop {string?} description
* @prop {string[]?} tags
* @prop {string} visibility
* @prop {number} crawledAt
* @prop {number} createdAt
* @prop {number} updatedAt
* @prop {LibraryArchiveMeta} author
*/
// globals
// =
const events = new Events()
const validateBookmark = schemas.getValidator('unwalled.garden/bookmark.json')
// exported api
// =
export const on = events.on.bind(events)
export const addListener = events.addListener.bind(events)
export const removeListener = events.removeListener.bind(events)
/**
* @description
* Crawl the given site for bookmarks.
*
* @param {DaemonDatArchive} archive - site to crawl.
* @param {CrawlSourceRecord} crawlSource - internal metadata about the crawl target.
* @typedef {Object} Reaction
* @prop {string} topic
* @prop {string[]} phrases
* @prop {string} author
* @prop {string} recordUrl
* @prop {number} crawledAt
*
* @typedef {Object} TopicReaction
* @prop {string} phrase
* @prop {string[]} authors
*/
// globals
// =
const events = new Events()
const validateReaction = schemas.getValidator('unwalled.garden/reaction.json')
// exported api
// =
export const on = events.on.bind(events)
export const addListener = events.addListener.bind(events)
export const removeListener = events.removeListener.bind(events)
/**
* @description
* Crawl the given site for reactions.
*
* @param {DaemonDatArchive} archive - site to crawl.
* @param {CrawlSourceRecord} crawlSource - internal metadata about the crawl target.
export default function watch ( rollup, options ) {
const watchOptions = options.watch || {};
if ( 'useChokidar' in watchOptions ) watchOptions.chokidar = watchOptions.useChokidar;
let chokidarOptions = 'chokidar' in watchOptions ? watchOptions.chokidar : !!chokidar;
if ( chokidarOptions ) {
chokidarOptions = Object.assign( chokidarOptions === true ? {} : chokidarOptions, {
ignoreInitial: true
});
}
if ( chokidarOptions && !chokidar ) {
throw new Error( `options.watch.chokidar was provided, but chokidar could not be found. Have you installed it?` );
}
const watcher = new EventEmitter();
const filter = createFilter( watchOptions.include, watchOptions.exclude );
const dests = options.dest ? [ path.resolve( options.dest ) ] : options.targets.map( target => path.resolve( target.dest ) );
let filewatchers = new Map();
let rebuildScheduled = false;
let building = false;
let watching = false;
let closed = false;
let timeout;
let cache;
function triggerRebuild () {
clearTimeout( timeout );
rebuildScheduled = true;
constructor(props){
super(props);
global.reactAlertEvents = new EventEmitter();
this.state = {
alerts: []
};
this.style = this._setStyle();
this.theme = this._setTheme();
this._eventListners();
}
/**
constructor() {
this.events = new events();
this.on = this.events.on;
}