Skip to content

⌛ A lightweight Node.js module that returns a promise-based interval, simplifying the execution of recurring tasks with flexible and reliable asynchronous control. Ideal for developers looking to manage intervals in a clean and efficient way.

License

Notifications You must be signed in to change notification settings

damartripamungkas/node-interval-return

Repository files navigation

NODE-INTERVAL-RETURN

GitHub top language Made by Repository size GitHub last commit


📖 Description :

This package is designed to run setInterval with several features. It includes functionalities such as returning a promise, executing a specific task first, stopping the interval, and automatically stopping the interval in the background if a return is triggered.

💻 Step to install :

npm install node-interval-return

✏️ Example :

full example see here

const { recursiveReturn, interval, intervalReturn } = require(`node-interval-return`)

// function recursiveReturn
await recursiveReturn((repeat, resolve, reject, state) => {
  console.log(`test recursiveReturn(), random: ${Math.random()}`)
  if (state.counter == 3) {
    return resolve(true)
  }

  repeat(1000)
  state.counter += 1
})

// function intervalReturn
await intervalReturn(1000, true, (resolve, reject, state) => {
  console.log(`test intervalReturn(), random: ${Math.random()}`)
  if (state.counter == 3) {
    return resolve(true)
  }

  state.counter += 1
})

// function interval
const resInterval = interval(1000, true, (stop, state) => {
  console.log(`test interval, random: ${Math.random()}`)
  if (state.counter == 3) {
    return stop()
  }

  state.counter += 1
})

🧾 Pre-Requisistes :

- node.js / bun.js / deno.js
- (optional) typescript
- (optional) commonJS
- (optional) ESM

📝 License :

Licensed see here.

About

⌛ A lightweight Node.js module that returns a promise-based interval, simplifying the execution of recurring tasks with flexible and reliable asynchronous control. Ideal for developers looking to manage intervals in a clean and efficient way.

Topics

Resources

License

Code of conduct

Security policy

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published