1.0.5 • Published 5 years ago

asyncinterval2 v1.0.5

Weekly downloads
5
License
ISC
Repository
github
Last release
5 years ago

asyncinterval2

How to use:

const Asyncinterval = require('asyncinterval2')

//Create an asyncintervalObject object
let interval = new Asyncinterval(async func,options);

//Start the interval
interval.start(delay);

//Stop the interval;
await interval.stop(wait);

Params:

  • func: a function with Promise return;
  • options: - time: interval time; - name: name of the job; - timeout: timeout of each job; - timeoutCallback: callback if the job has been timeout; - log: log level,can be "info":every job info, "error": if error occurred.

  • delay: delay milliseconds to start the job

  • wait: if true, will wait till job finished of timeout.

Example:

const Asyncinterval = require('asyncinterval2')

let options = {
    time: 500,
    name: "mytester",
    timeout: 5000,
    timeoutCallback: () => {
        console.log("timeout!!");
        //to something
    },
    log: "info"
}

let job = () => {
    return new Promise(resolve => {
        //job example
        setTimeout(() => {
            console.info("Asyncinterval job run finished")
            resolve(1)
        }, 6000);
    })
}

let myInterval = new Asyncinterval(job, options);

myInterval.start(100);

// stop() test here:
// setTimeout(async ()=>{
//     console.log(await myInterval.stop(true));
// },2000);
1.0.5

5 years ago

1.0.4

5 years ago

1.0.3

5 years ago

1.0.2

6 years ago

1.0.1

6 years ago