Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

wish: named forks #17

Open
axkibe opened this issue Feb 21, 2014 · 3 comments
Open

wish: named forks #17

axkibe opened this issue Feb 21, 2014 · 3 comments

Comments

@axkibe
Copy link

axkibe commented Feb 21, 2014

I'd wish I could call fork with names.

var sus = require( 'suspend' )
fs.readFile( 'a.txt', sus.fork( "a" );
fs.readFile( 'b.txt', sus.fork( "b" );
var joi = sus.join();
console.log( joi.a, joi. b);

Would give nice code rather than counting fork

Additionally not an issue but a question. Say I got a generator which wants to runs two generators in parallel - that is starting the second generator when the first one yields. Then waits until both are finished. How'd one approach this?

@axkibe
Copy link
Author

axkibe commented Feb 21, 2014

BTW: suspend is great! After trying various approaches the last years, I'm currently settling on this :-)

@jmar777
Copy link
Owner

jmar777 commented Feb 22, 2014

@axkibe Happy to hear suspend is working well for you, and thanks for saying so!

I think your idea for named forks is a good one, and I can't think of any other obvious use for a single string parameter to fork(). Let me stew it over for a little bit, but initially I like it.

@axkibe
Copy link
Author

axkibe commented Feb 23, 2014

I gave some more thought about this, and I think there might be better ways than using join, if its implementable ( i don't know :-) something like this would be awesome:

var
    sus = require( 'suspend' ),
    a = sus( fs.readFile( 'a.txt', sus.callback() ),
    b = sus( fs.readFile( 'b.txt', sus.callback() );

try
{
console.log( yield a.data( ) );
console.log( yield b.data( ) );
}
catch ( err )
{
/// error handler
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants