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

retry: add predicate option (currently only function) #123

Merged

Conversation

adrian-gierakowski
Copy link
Contributor

Predicate function is executed with rejection value, if the call returns
a truthy value then the handler is retried, otherwise the promise is
rejected with the original rejection value

Predicate function is executed with rejection value, if the call returns
a truthy value then the handler is retried, otherwise the promise is
rejected with the original rejection value
@adrian-gierakowski
Copy link
Contributor Author

partially addresses #122

@suguru03 I decided to implement only the predicate function at first since I need this functionality immediately

Regarding implementing the interface based on assert.rejects I am not sure if it's ok to simply require('assert') given that your library should also work in the browser. I am guessing that you are using something like browserify, which should take care of shimming the assert module?

Copy link
Owner

@suguru03 suguru03 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@suguru03 suguru03 merged commit bf33123 into suguru03:master Apr 13, 2020
@suguru03
Copy link
Owner

Thanks!
I need to fix some dependencies, I'm gonna release it by the end of day.

@suguru03
Copy link
Owner

@adrian-gierakowski
I published it on 1.15.0-alpha.0.
You should be able to install it using npm install aigle@next 🙂

I will fix a travis issue tomorrow.

@adrian-gierakowski
Copy link
Contributor Author

adrian-gierakowski commented Apr 14, 2020 via email

@suguru03
Copy link
Owner

@adrian-gierakowski Sorry for the late reply!

I'm thinking about something like this,

class CustomError extends Error {}
const errorRetry = new CustomError('retry');
// instance
const retryOpts = { limit, predicate: errorRetry };
// or class?
const retryOpts = { limit, predicate: CustomError };
return Aigle.retry(retryOpts, () => {});

What do you think? 🤔

I usually use assert.rejects(promise, errrorRetry) and it's really useful.

@adrian-gierakowski
Copy link
Contributor Author

@adrian-gierakowski Sorry for the late reply!

I'm thinking about something like this,

class CustomError extends Error {}
const errorRetry = new CustomError('retry');
// instance
const retryOpts = { limit, predicate: errorRetry };
// or class?
const retryOpts = { limit, predicate: CustomError };
return Aigle.retry(retryOpts, () => {});

What do you think? 🤔

I usually use assert.rejects(promise, errrorRetry) and it's really useful.

Looks good. So I'm assuming I'll be ok to use 'assert' module to implement this and it will be shimmed by whatever library you use to create the browser release?

@suguru03
Copy link
Owner

I would rather add some code than depend on other libraries. I'm also thinking to support Deno in the future. 😄
Could you add the handling? I don't think it is a big change.

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

Successfully merging this pull request may close these issues.

2 participants