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

Make never propagate #30

Open
bergus opened this issue Jul 13, 2016 · 4 comments
Open

Make never propagate #30

bergus opened this issue Jul 13, 2016 · 4 comments

Comments

@bergus
Copy link
Contributor

bergus commented Jul 13, 2016

never() claims to "consume virtually no resources". However, this is no more true if never is used in any combinator, especially merge/all/settle. Should we detect nevers, and futures that eventually resolve to a never there and set the result accordingly?

If we want to do that, any ideas about the how? Should Action implement an onNever handler that is called by Never::_runAction?

@briancavalier
Copy link
Owner

I believe it's mostly true: never itself does consume almost no resources, and near() will tend to collapse promise chains over time.

I'd thought about detecting never and short circuiting in merge/all/settle (I think I even wrote the code for it at some point), and I still think it's a pretty cool idea. I ended up believe that real world usages of never will be few and far between, and so I didn't feel like the extra code was worth it. I could definitely be convinced that it's worthwhile, tho, if the code to do it is extremely small and simple.

@bergus
Copy link
Contributor Author

bergus commented Jul 13, 2016

Yes, real-world usages of never seem to be rare. I wonder if anyone used it as a poor-mans cancellation, otherwise I can hardly imagine use cases.
If anything, it might have been used in the monoid instance together with concat, but that one already is short-circuited.

@briancavalier
Copy link
Owner

I wonder if anyone used it as a poor-mans cancellation

That's an interesting question. I hadn't even considered it :) Now I'm wondering what that would look like ... any chance you've tried it?

@bergus
Copy link
Contributor Author

bergus commented Jul 14, 2016

I mean something like

let isCancelled = false;
cancelButton.onclick = () => { isCancelled = true; … };
….then(r => {
    if (isCancelled) return never();
    …
}).then(r => {
    if (isCancelled) return never();
    …
})

@bergus bergus mentioned this issue Jul 28, 2016
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