private static setupConnection(url: string, token: AccessToken, config: any): void { SocketConnections.configured = true; console.log('Connected to %s', url); SocketConnections.connections[url].emit('authentication', token); SocketConnections.connections[url].on('unauthorized', (res: any) => console.error('Unauthenticated', res)); setInterval(() => SocketConnections.connections[url].emit('lb-ping'), 15000); SocketConnections.connections[url].on('lb-pong', (data: any) => console.info('Heartbeat: ', data)); SocketConnections.connections[url].on('disconnect', (data: any) => { console.info('Unexpected disconnection from IO - Socket IO will try to reconnect'); }); }
start() { if (this.ref) { return; } this.runOnce(); this.ref = setInterval(() => this.runOnce(), this.interval); }
componentDidMount() { const { children } = this.props; this.setState({ total: Children.count(children) }); this.interval = setInterval(this.showNext, 2000); }
componentDidMount() { this.timer = setInterval(() => { Api.fetchDraftPost(this.props.url.query.id).then(post => { this.setState({ post }); }); }, 1000); }
http.createServer((req, res, next) => { res.writeHead(200, { 'content-encoding': 'gzip' }); const output = zlib.createGzip(); output.pipe(res); setInterval(() => { output.write(`The current time is ${Date()}\n`, () => { // The data has been passed to zlib, but the compression algorithm may // have decided to buffer the data for more efficient compression. // Calling .flush() will make the data available as soon as the client // is ready to receive it. output.flush(); }); }, 1000); }).listen(8082, () => { console.log('Server started at port 8082'); });
start(cb) { if (!this.interval) { this.startTime = moment(); this.interval = setInterval(() => { this.duration -= this.delay; this.updateDisplay(); this.listenForExpiration(); }, this.delay); return cb ? cb() : null; } }
const timerMiddleware = store => next => (action) => { const newAction = { ...action }; switch (action.type) { case 'START_TIMER': newAction.tickInterval = setInterval(() => store.dispatch({ type: 'TICK_TIMER' }), 1000); return next(newAction); case 'STOP_TIMER': clearInterval(store.getState().tickInterval); return next(newAction); case 'PAUSE_5SECS': console.log('initiating MW PAUSE_5SECS'); return setTimeout(() => next(newAction), 5000); default: } return next(newAction); }
initialize() { return super.initialize() .tap(() => { // Schedule periodic parent process ping to handle case when // parent process is killed with SIGKILL. setInterval(() => { this._pingParent().catch(err => { this.getLog().error('Parent ping failed: ' + err); return this.getSystem().destroy(); }); }, Math.round(this.pingTimeout / 3)); }); }
setInterval(()=>this.onProgress(torrent), 500)
static getHandler(url: string, token: AccessToken) { if (!SocketConnections.connections[url]) { console.log('Creating a new connection with: ', url); let config: any = { log: false, secure: false, forceWebsockets: true }; SocketConnections.connections[url] = SocketDriver.connect(url, config); SocketConnections.connections[url].on('connect', () => { if (!SocketConnections.configured) SocketConnections.setupConnection(url, token, config); }); let forceConfig: any = setInterval(() => { if (!SocketConnections.configured && SocketConnections.connections[url].connected) { console.info('Forcing IO Configuration'); SocketConnections.setupConnection(url, token, config); clearInterval(forceConfig); } else if (SocketConnections.configured) { clearInterval(forceConfig); } }, 1000) } else { console.log('Reusing existing connection: ', url); } return SocketConnections.connections[url]; }
const AnimalContainer = ({ animals, berry, sortDirection, toggleFavorite, giveBerry, pruneBerries }) => { const [time, setTime] = useState(Date.now()); useEffect(() => { pruneBerries(Date.now()); const interval30Sec = setInterval(() => { setTime(Date.now()); pruneBerries(Date.now()); }, 20000); return () => clearInterval(interval30Sec); }, []); return ( <Animals animals={animals} sortDirection={sortDirection} toggleFavorite={toggleFavorite} giveBerry={giveBerry} time={time} berry={berry} /> ); }
/** * Enables remote endpoint monitoring. * * @private */ _monitorChild() { this.connectivityCheckStartTimeout = setTimeout(() => { this.connectivityCheckInterval = setInterval(() => { let lastPingTs = this._getLastReceiveTimestamp() || 0; let now = _.now(); if (now - lastPingTs > this.getSystem().getPingTimeout()) { this._setState('crashed'); this.getLog().warn('Attempting to respawn remote endpoint due to timeout...'); this.actorSocket && this.actorSocket.destroy(); clearInterval(this.connectivityCheckInterval); this._respawn(); } }, 1000); }, this.getSystem().getPingTimeout()); }
init() { // load custom settings SettingsManager.loadSettings(); // load characters Characters.loadCharacters(true); Characters.loadGameServers(); // watch button interactions ButtonActions.watch(); // show lodestone news Lodestone.showNews(); // this is on a loop so that if a character does not exist on the API, // then hopefully in the next few minutes it will. Current settings // is every 1 minute, if a character is on the API then it is not // queried anymore times. Characters.populateCharacterData(); setInterval(() => { Characters.populateCharacterData(); }, Settings.custom.xivapiPollDelay); }
componentWillMount() { this.setState({ exchanges: [] }); // simulate data changes this.__intervalHandle = setInterval(p => {// load data const data = this.getData(); // convert data to our model for (let item of data) { const split = item.pair.split(" "); item.exchangeFromName = split[0]; item.exchangeToName = split[1]; } this.setState({ exchanges: data }); }, 1000); }
/** * Adds an animated progress indicator * * @param {string} message The message to write next to the indicator * @param {number} amountOfDots The amount of dots you want to animate */ function animateProgress(message, amountOfDots) { if (typeof amountOfDots !== 'number') { amountOfDots = 3; } let i = 0; return setInterval(function() { readline.cursorTo(process.stdout, 0); i = (i + 1) % (amountOfDots + 1); const dots = new Array(i + 1).join('.'); process.stdout.write(message + dots); }, 500); }