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

Allow wrapping function like mem does #61

Open
fregante opened this issue Mar 19, 2022 · 2 comments
Open

Allow wrapping function like mem does #61

fregante opened this issue Mar 19, 2022 · 2 comments

Comments

@fregante
Copy link

Instead of passing a function to immediately call it, I'd like to wrap a function to be used later. From:

function runMeNow() {}
function init() {
	pRetry(runMeNow, {
		bigOptionsObject
	}).then(console.log)
}

init();

to:

const runMeRetried = pRetry.wrap(runMeNow, {
	bigOptionsObject
});
function init() {
	runMeRetried.then(console.log)
}

init();
@sindresorhus
Copy link
Owner

Sure. It should probably be a named export though. Naming suggestions?

  • makeRetriable
  • createRetry

@ghost
Copy link

ghost commented Apr 28, 2022

I was looking for something to handle retries and i found this and node-retry. node-retry has retry.wrap https://github.com/tim-kos/node-retry#retrywrapobj-options-methodnames which can wrap an entire object's methods or just specific methods.

I ended up going with p-retry due to ts support, but wrap seemed very useful for a particular object I have.

@fregante fregante changed the title Allow wrapping function like mem Allow wrapping function like mem does Apr 28, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants