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

Clear timeout after aborting pending executions #14

Merged
merged 1 commit into from
Feb 18, 2019

Conversation

edy
Copy link
Contributor

@edy edy commented Jan 29, 2019

abort() doesn't clear the timeout of pending executions. thus all executions will execute after abortion.

abort() doesn't clear the timeout of pending executions. thus all executions will execute after abortion.
@edy
Copy link
Contributor Author

edy commented Jan 29, 2019

Example

const pThrottle = require('p-throttle');
const now = Date.now();
const throttled = pThrottle(
	(index) => {
		console.log('execute');
		const secDiff = ((Date.now() - now) / 1000).toFixed();
		if (Math.random() > 0.5) {
			return Promise.reject('TEST');
		}
		return Promise.resolve(`${index}: ${secDiff}s`);
	},
	1,
	1000
);

for (let i = 1; i <= 6; i++) {
	throttled(i).catch((e) => {
		console.error(e);
		throttled.abort();
	});
}

@sindresorhus sindresorhus changed the title clear timeout after aborting pending executions Clear timeout after aborting pending executions Feb 18, 2019
@sindresorhus sindresorhus merged commit 98b8506 into sindresorhus:master Feb 18, 2019
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.

None yet

2 participants