Skip to content

Instantly share code, notes, and snippets.

@arturovt
Last active July 27, 2019 16:35
Show Gist options
  • Save arturovt/abce8050b6916c7135fac4716b1a3397 to your computer and use it in GitHub Desktop.
Save arturovt/abce8050b6916c7135fac4716b1a3397 to your computer and use it in GitHub Desktop.
function scheduleTask(task) {
var data = task.data;
function timer() {
try {
task.invoke.apply(this, arguments);
} finally {
if (!(task.data && task.data.isPeriodic)) {
if (typeof data.handleId === 'number') {
// в не nodejs окружении `timerId`
// хранится в кеше и удаляется по завершении
delete tasksByHandleId[data.handleId];
}
}
}
}
data.args[0] = timer;
data.handleId = setNative.apply(window, data.args);
return task;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment