-
Notifications
You must be signed in to change notification settings - Fork 0
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
No way to stop a running task inside the callback #6
Comments
Hello, If you declare your var PeriodicTask = require('periodic-task');
var i = 0;
var task = new PeriodicTask(1000, function () {
console.log(i++);
if (i > 3) {
task.stop();
}
});
task.run(); Thank you for your feedback! By the way, as stated in the README, have you considered using async-polling instead of this project? var AsyncPolling = require('async-polling');
var i = 0;
AsyncPolling(function (end) {
console.log(i++);
if (i > 3) {
this.stop();
}
end();
}, 1000).run(); |
Hi, You are right about the first solution, but my situation is a bit more complicated. I have the callbacks declared before and No I have not tried Thanks anyway. Sayantan ... |
I am going to erase the README of this project, advising to go for async-polling instead. I think it is more relevant to use an asynchrone compliant library in JavaScript, so I prefer to improve async-polling and remove periodic-task. |
Ok, would you consider to mention it as deprecated in the NPM repo? I mean here. |
That's a good idea. I'll do this. Thank you for your advice! |
You are welcome. |
Hi,
I am using periodic task in my project. I came across a situation where I needed to stop the task from within the callback. As the API suggests to instantiate a task as below,
var task = new PeriodicTask(delay, callback, [context], [args])
I cannot pass the task
task
instance into thecallback
to issuetask.stop()
inside it.I suggest a workaround here.
var obj = {};
var task = new PeriodicTask(delay, callback, obj, args);
obj.stop = task.stop.bind(task);
If there is any better approach I would appreciate if you inform me. Otherwise would you like to provide a workaround in the API?
Thanks.
Sayantan ...
The text was updated successfully, but these errors were encountered: