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

Don't catch errors in resolve fns, chains, etc... #127

Closed
jordalgo opened this issue Sep 17, 2016 · 4 comments
Closed

Don't catch errors in resolve fns, chains, etc... #127

jordalgo opened this issue Sep 17, 2016 · 4 comments

Comments

@jordalgo
Copy link

Unnecessary error catching is something that, IMO, we should avoid in Future/Task implementations. e.g.

function createFuture() {
  return new Future(function computation(reject, resolve){
    setTimeout(() => {
      resolve('hello');
    }, 0);
  });
}

createFuture().fork(
  left => { console.log('left', left.message); },
  right => { console.log('right', right); throw new Error('boom'); }
);

This example will log in the console:
right hello
left boom

This is not good as it's completing the future twice and mixing rejections with unexpected errors (something that Promises do). If there is code that might be prone to throwing an error (such as JSON.parse or accessing nested props in an object) THAT code should get wrapped in a try/catch. The Future/Task should have no opinion on error catching.

@davidchambers
Copy link
Member

+:100:

@Avaq
Copy link
Contributor

Avaq commented Sep 18, 2016

Related:

@jordalgo
Copy link
Author

@Avaq Thanks for the links. I had read @rpominov 's philosophy a little while ago and I agree 100%. It also seems like you agree which is why you don't have any special error handling in Flutures. What do you think about removing it for Ramda's Future?

On a related topic (and I can move this into a separate issue), is there any spec out there for Futures/Tasks in javascript and if not, is it worth making one? It's probably not completely neccesary but it might be nice to standardize this type in some way (fork vs run, error handling, Future or Task, etc...) similar to the work going on with Observables -- though I feel like standardizing on Future/Task would be MUCH easier 😜

@Avaq
Copy link
Contributor

Avaq commented Feb 11, 2018

I believe this can be closed. Ramda Fantasy has been discontinued, and recommends using Fluture. Fluture doesn't mix exceptions into the rejection branch.

I don't think standardising Future continuation is beneficial in the long run (see Promises). It's nice that the community can come up with different ways of abstracting over asynchronous computations.

Work is being done to standardise catamorphism though, which comes close.

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

3 participants