Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@danieldiekmeier/async-worker

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@danieldiekmeier/async-worker

A simple worker to do work in intervals

  • 1.0.0
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

Async Worker

npm i @danieldiekmeier/async-worker

Usage

Do you have a task that needs to run every now and then? Do you not want to worry about setting up a cronjob, but also not just slap a setInterval on it and call it a day? Then this package is the middle ground for you.

Put your worker logic somewhere in your application logic, reuse all your stuff, it's going to be fine!

✨ async/await is fully supported and encouraged ✨

Here is a code example:

import Worker from '@danieldiekmeier/async-worker'

new Worker({
  // This function is called on every task execution.
  async task () {
    await database.removeOldStuff()
  },

  // Set the minimum time between task executions, in milliseconds (ms).
  // In this case, it would run once per hour.
  interval: 60 * 60 * 1000,

  // Whenever the task errors, this function is called with the error.
  onError (err) {
    fancyLogger(err)
  }
})

The Worker doesn't start the task if the previous execution is still running. That way, you don't have to worry about having long running tasks like complex database cleanup or slow download tasks.

Keywords

FAQs

Package last updated on 19 Feb 2019

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc