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);
	}
});
Example #3
0
  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}))
  })
Example #4
0
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) {
Example #6
0
    setTimeout(() => {
        const stubs = {
            '/search?name=iPhone': 123,
            '/shopOffers?id=123': ['AppleStore', 'DNS']
        };

        csp.putAsync(ch, stubs[url]);
    }, 1000);
Example #7
0
    C.go(function*(){
      while (step !== C.CLOSED){
        var step = yield animator;
        transactor(step);
      }

      C.putAsync(doneChan);
      animator.close();
      doneChan.close();
    });
Example #8
0
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 })
  }
})
Example #9
0
    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();
    });
Example #10
0
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);
});
Example #11
0
 el.addEventListener(action, function (event) {
     putAsync(ch, event);
 });
Example #12
0
 requestAnimationFrame(() => {
   C.putAsync(animSteps);
 });
Example #13
0
 server.listen(null, () => {
   csp.putAsync(portCh, server.address().port)
 })
Example #14
0
});

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';
    }

});



Example #15
0
 app.post('/worker/:id/running', (req, res) => {
   instructionChMap = instructionChMap.set(req.params.id, csp.chan())
   csp.putAsync(workerActiveCh, req.params.id)
   res.end()
 })
Example #16
0
 ps.on('close', code => putAsync(exitCh, {code}))
Example #17
0
 .on('data', data => putAsync(stdoutCh, data))
Example #18
0
 exec(cmd, opts, function (err, stdout) {
   if (err) csp.putAsync(ch, err)
   csp.putAsync(ch, stdout.trim())
 })
Example #19
0
 setTimeout(() => {
   console.log('Push 2 more tasks');
   for (; i <= 12; i++) {
     csp.putAsync(queue, i);
   }
 }, 5000);
Example #20
0
setTimeout(function () {
    putAsync(broadcast, 'message 1');
    putAsync(broadcast, 'message 2');
    putAsync(broadcast, 'message 3');
}, 100);
Example #21
0
 Mousetrap.bind(key, function() {
   csp.putAsync(ch, key);
 });
Example #22
0
 app[method](path, (req, res) => {
   csp.putAsync(ch, req.body)
   ch.close()
   res.end()
 })