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

putAsync/takeAsync should return a Promise #109

Open
tmtxt opened this issue Dec 5, 2016 · 10 comments
Open

putAsync/takeAsync should return a Promise #109

tmtxt opened this issue Dec 5, 2016 · 10 comments

Comments

@tmtxt
Copy link

tmtxt commented Dec 5, 2016

Just like their names, these functions should return a Promise (maybe when no callback function specified)

  • putAsync
  • takeAsync

Use with es7 async/await function

await putAsync(ch, 42);
...
var res = await takeAsync(ch);

Use with other libraries like co

yield putAsync(ch, 42);
...
var res = yield takeAsync(ch);
@XVincentX
Copy link

I totally agree with this - I would probably get rid of the callbacks completely, but that would be a breaking change
@hung-phan - any thoughts from your side?

@hung-phan
Copy link
Collaborator

Quite a big change, but let me see if I could support it. By the way, I don't use putAsync much, I usually just create a go block and use put.

@XVincentX
Copy link

From my personal side, I also do not use it that much (there are some edge cases where I should).

Just out of curiosity, are you using js-csp in production somewhere? Are you willing to share some informations, eventually @hung-phan

@hung-phan
Copy link
Collaborator

Ah I just use it for some companies project (not open-source) to handle complex state. For example, implement the behavior of Om cursor (but I think they already go with query expression) to control the application state, implement pubsub like flux, or use it with redux.

@tmtxt
Copy link
Author

tmtxt commented Dec 15, 2016

Many projects are already written in koa/co (in our company projects) and it's would be nice if we can still follow our own coding style instead of wrapping inside one go block (1 more nested level).

Btw, js-csp can be helpful in batch processing and memory constraint environment where we would force one task to wait for another task to finish processing the data before it can continue (or drop the data) using the channel instead of pushing too much data into the queue and fill up the memory.

@ubolonton
Copy link
Contributor

One way to go about this is to provide alternatives to process.js, which integrate with different coroutine systems instead of implementing one (which is basically what process.js does), then make the choice configurable somehow. Most of the integration should be straightforward, except for how errors are handled/propagated.

@XVincentX
Copy link

Does anybody of you have nice experience of using CSP to handle complex User Interface scenarios?

@hung-phan
Copy link
Collaborator

hung-phan commented Dec 24, 2016

yes 🤔

@XVincentX
Copy link

@hung-phan Cool - are you willing to share some informations? I would be really interested.

@corporatepiyush
Copy link

@XVincentX refer this article for using CSP in UI with ReactJS
http://lucasmreis.github.io/blog/using-csp-as-application-architecture/

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

5 participants