Reputation: 21
Searching through the VS Code API I cannot see any functions that would allow me to call a function on a regular basis from a timer.
I have tried setInterval and setTimeout, but they do not seem to be natively supported with the vscode API.
Upvotes: 0
Views: 1553
Reputation: 3219
private repeat: number = setInterval(() => { console.log('called') }, 5000);
Sorry this is javascript not typescript but maybe it can help you anyway. This is from one of my vscode extensions and it is working nicely. Function is called every half second.
const vscode = require('vscode');
function activate(context) {
const someFunction = function () {
console.log('called');
};
setInterval(someFunction, 500);
}
exports.activate = activate;
Upvotes: 0
Reputation: 1233
I developed an extension that runs a particular task after every X seconds. Initially, I have used setInterval method, however later I realized that it is not suitable for complex cases. So then I moved to cron because that gives me greater control than setInterval method.
By using cron I can programmatically start/stop the timer plus with the cron expression, it becomes much easier to configure interval periods.
Note: I did not find any native method in VS Code API and that is when I looked for these options.
Upvotes: 2