csp.go(function* () { var body; var value = yield take(internal.action); console.log('Starting inbound wait channel loop'); while (value !== csp.CLOSED) { if (value != undefined) { if (yield helper.verifyRequest(value.request)) { body = yield processRequest(value.request.params, value.route_type); } else body = yield helper.buildMessageTwiml('Failed to verify message. Goodbye'); //hack to get around bug in when library that doesn't unwrap nested promises if (typeof body === 'string') { value.body = body; csp.putAsync(outbound, value); } else if (typeof body === 'object') { body.then(function(resp){ console.log('GOOD: ', resp) if (value != undefined) { value.body = resp; csp.putAsync(outbound, value); } }).catch(function(e) { console.log('BAD: ', e) }); } else { value.body = undefined; csp.putAsync(outbound, value); } } value = yield take(internal.action); } });
csp.go(function* () { var body; var isValid = false; var value = yield take(internal.calls); console.log('Starting inbound call channel loop'); while (value !== csp.CLOSED) { if (value != undefined) { if (yield helper.verifyRequest(value.request)) { body = yield processRequest(value.request.params, value.route_type); } else body = yield helper.buildMessageTwiml('Failed to verify message. Goodbye'); if (typeof body === 'string') { value.body = body; csp.putAsync(outbound, value); } else if (typeof body === 'object') { body.then(function(resp){ console.log('GOOD: ', resp) if (value != undefined) { value.body = resp; csp.putAsync(outbound, value); } }).catch(function() { console.log('BAD') }); } else { value.body = undefined; csp.putAsync(outbound, value); } } value = yield take(internal.calls); } });
request.get(url, {json: {}}, (err, res, body) => { if (err) { return putAsync(ch, immutable.fromJS({err: err})) } putAsync(ch, immutable.fromJS({status: res.statusCode, body: body})) })
function handleResult(ch, err, res) { if (err) { csp.putAsync(ch, { error: err }); } else { csp.putAsync(ch, { data: res.body, ok: true }); } }
body.then(function(resp){ console.log('GOOD: ', resp) if (value != undefined) { value.body = resp; csp.putAsync(outbound, value); } }).catch(function(e) {
setTimeout(() => { const stubs = { '/search?name=iPhone': 123, '/shopOffers?id=123': ['AppleStore', 'DNS'] }; csp.putAsync(ch, stubs[url]); }, 1000);
C.go(function*(){ while (step !== C.CLOSED){ var step = yield animator; transactor(step); } C.putAsync(doneChan); animator.close(); doneChan.close(); });
chokidar.watch(process.cwd(), { ignored }).on('all', (event, filePath) => { // Reload hactar // TODO: make this work with plugins running on a loop if (filePath.indexOf('hactar.config-plugin.js') > -1) { console.log('loading Hactar config') delete require.cache[hactarCustomizationPath] tryLoadHactarConifg() } switch (event.toUpperCase()) { case 'ADD': putAsync(ch, { type: 'ADD_FILE', path: filePath }) break case 'CHANGE': putAsync(ch, { type: 'CHANGED_FILE', path: filePath }) break default: putAsync(ch, { type: event.toUpperCase(), path: filePath }) } })
C.go(function*(){ while (elapsed < duration){ requestAnimationFrame(() => { C.putAsync(animSteps); }); animStep = yield animSteps; var x = E[type](elapsed / duration); C.putAsync(easeSteps, x); elapsed = Date.now() - start; } animSteps.close(); easeSteps.close(); });
csp.go(function* () { var queue = csp.chan(); var i = 1; csp.go(consumer, [queue]); for (; i <= 10; i++) { csp.putAsync(queue, i); } console.log('Done pushing 10 tasks'); console.log('Wait for processing to be done'); setTimeout(() => { console.log('Push 2 more tasks'); for (; i <= 12; i++) { csp.putAsync(queue, i); } }, 5000); setTimeout(() => { console.log('Should be done by now, close queue'); queue.close(); }, 15000); });
el.addEventListener(action, function (event) { putAsync(ch, event); });
requestAnimationFrame(() => { C.putAsync(animSteps); });
server.listen(null, () => { csp.putAsync(portCh, server.address().port) })
}); Template.hello.events({ 'click button' (event, instance) { // increment the counter when button is clicked instance.counter.set("1"); console.log(instance.counter.get()); go(function*() { put(chDuck, "+ > clicking button"); }); }, }); let chantimed = chan(); putAsync(chantimed, 'true'); Template.sheet.helpers({ loaded() { go(function*() { yield take(chantimed); console.log('+ headerslpash') }); return 'loaded'; } });
app.post('/worker/:id/running', (req, res) => { instructionChMap = instructionChMap.set(req.params.id, csp.chan()) csp.putAsync(workerActiveCh, req.params.id) res.end() })
ps.on('close', code => putAsync(exitCh, {code}))
.on('data', data => putAsync(stdoutCh, data))
exec(cmd, opts, function (err, stdout) { if (err) csp.putAsync(ch, err) csp.putAsync(ch, stdout.trim()) })
setTimeout(() => { console.log('Push 2 more tasks'); for (; i <= 12; i++) { csp.putAsync(queue, i); } }, 5000);
setTimeout(function () { putAsync(broadcast, 'message 1'); putAsync(broadcast, 'message 2'); putAsync(broadcast, 'message 3'); }, 100);
Mousetrap.bind(key, function() { csp.putAsync(ch, key); });
app[method](path, (req, res) => { csp.putAsync(ch, req.body) ch.close() res.end() })