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

Support for 'throw' inside worker #29

Open
YarnSphere opened this issue Mar 31, 2015 · 3 comments
Open

Support for 'throw' inside worker #29

YarnSphere opened this issue Mar 31, 2015 · 3 comments
Assignees

Comments

@YarnSphere
Copy link

Hi! First of all, I've only been using this library for a few days and I already find it awesome, so: thank you for creating it, your work is definitely appreciated!
My issue can probably be considered a request: I'm not certain that this is possible (I believe it should be), since I haven't looked into the source. What I would like to do is the following:

var test = operative(function() {
  throw 'Error'; // Throw an error instead of using deferred.reject
});

test().then(
function() {},
function(e) {
  console.error(e);
});

Is this possible? Is this not a good idea?
Thank you for your time and for your work!

@padolsey
Copy link
Owner

padolsey commented Apr 8, 2015

Glad you're enjoying Operative :)

Throwing inside of an operative method should probably already result in a rejected promise but somehow I missed that, so thanks for bringing it up! I'll try to get this into 0.4.0rc2 (and formally 0.4.0) which is currently being worked on.

@padolsey padolsey added this to the 0.4.0 milestone Apr 8, 2015
@padolsey padolsey self-assigned this Apr 8, 2015
@padolsey
Copy link
Owner

padolsey commented Apr 9, 2015

Actually, thinking about this more...

I'm not sure of the correct semantics here. Plus I think there needs to be more thought given to what happens in the non-promise case. There is always an implicit promise, but if people aren't listening for a rejection then an error might not be noticed at all... which is definitely bad.

Out of curiosity, what is your use case? Is it the case that your operative-method's logic throws legitimate errors? If so, can you just formally reject() it internally?

@padolsey padolsey removed this from the 0.4.0 milestone Apr 9, 2015
@YarnSphere
Copy link
Author

I'm not sure about the semantics either. After making the request I also thought a bit more about it and wasn't so sure whether it should be implemented.

In my case, I was trying to write functions that could be used both inside or outside a web worker. Raising exceptions is common practise when writing a regular function - I'd like to be able to also see the raised exception if the function is running inside a worker. Using deferred.reject makes no sense in a non-worker environment.

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