BackgroundService
The class is very simple and only has a name and a main function.
It has been thought to work with polling services, and the general idea is to build the main function with a while true and a sleep.
This is a basic example of a background service icrementing a counter every 2 seconds
import { BackgroundService, sleep } from 'expresso-macchiato';
export const sayngHiService = new BackgroundService({
name: 'sayngHi',
main: async () =>
{
let counter:number = 0;
while (true)
{
// Your code
counter++;
await sleep(2000);
}
}
});
Last updated