Giter Site home page Giter Site logo

chan's People

Contributors

brentropy avatar eugeneware avatar madbence avatar tj avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

chan's Issues

error handling

something like this?

var ch = chan();

co(function*() {
  fs.readFile('file', ch);

  try {
    var contents = yield ch;
  } catch(err) {
    // handle the fs error
  }
});

push a generator/generator function to a channel?

co(gen)(ch)

could be simplified by a method like:

ch.push(gen)

or something. only real benefit is that you won't have to require('co') all the time in addition to require('chan'). not really a big deal - you can close if you don't want it :P

i see problems with this, so meh

example with emitters

i.e. if i want to do fs.createWriteStream().on('finish', ch).on('error', ch)

note: i'm opening up an issue instead of a PR because i expect there to be tests :P

Why do I run a while loop when I use Chan and jump out of the function after the loop without executing the code after the loop?

const chan = require('chan');
const ch = chan();
async function parts(fn) {
return new Promise(function (resolve, reject) {
ch(function (err, res) {
if (err) return reject(err)
resolve(res);

    })
})

}
let count = 0;

const tick=setInterval(async () => {
if(count==3){
clearInterval(tick);
}else{
count++;
await ch(count);
}

}, 4000);

async function fun() {
let part;
const a = await 4;
while (
(part =await parts()
) != null
) {
console.log(part);
}
console.log(a);
}
fun()
//console
//1
//2
//3
console.log(a); doesn't work

doc: an example doesn't work

While reading the doc at https://github.com/brentburg/chan#sending-values-to-the-channel, it appears that this code should execute the callback:

ch('foo')(function (err) {
  if (err) {
    // There was an error putting the value on the channel
  } else {
    // The value was successfully put on the channel
  }
})

In fact, it doesn't execute the callback (when ch = makeChan()).
Did you mean a buffered channel here?

P.S. Or maybe add a "yield ch" block that would make it work?

Your channels are co-compatible unlike js-csp, that's cool.

Buffered channel

Is it possible to create buffered channels that behave similarly to their go counter parts?

Feature Request: chan.select()

Hi Brent,

Really loving this module. It's great to be able to use CSP-style concurrency in node.js!

The only roadblock I've found when using chan is that there's no easy way to be able to do the equivalent of a select.

Ideally I'd love to be able to write the following co code:

var co = require('co'),
    chan = require('chan');
co(function *(){
  var ch1 = chan(),
      ch2 = chan();

  var ch = yield chan.select([ch1, ch2]);
  switch (ch) {
    case ch1:
      var val1 = yield ch1;
      break;

    case ch2:
      var val2 = yield ch2;
      break;
  }
})();

There are lots of times where being able to use multiple channels (such as one for a timeout for example) is really useful, and currently there is no easy way to atomically wait for activity on multiple channels.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.