New:Introducing Socket Scanning for VS Code Marketplace Extensions.Learn more →
Get Started

@eggjs/background-task

Package Overview
Dependencies
Maintainers
10
Versions
39
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@eggjs/background-task

background task util for tegg

Source
npmnpm
Version
4.0.2
Version published
Weekly downloads
488
-83.42%
Maintainers
10
Weekly downloads
 
Created
Source

@eggjs/background-task

NPM version Known Vulnerabilities npm download Node.js Version

install

npm i --save @eggjs/background-task

Usage

import { BackgroundTaskHelper } from '@eggjs/background-task';

@ContextProto()
export default class BackgroundService {
  @Inject()
  private readonly backgroundTaskHelper: BackgroundTaskHelper;

  async backgroundAdd() {
    this.backgroundTaskHelper.run(async () => {
      // do the background task
    });
  }
}

Background

tegg release the request context after request is done. So use the process.nextTick, setTimeout, setInterval in request is not safe. Please use the backgroundTaskHelper, the release process will wait all the background tasks are done.

Timeout

The release process will wait tasks done, but not forever. The default timeout is 5s, if task will cost more than 5s, two ways to resolve

  • use the SingletonProto to do the work, SingletonProto never release
  • set longer timeout to backgroundTaskHelper.timeout

Keywords

async

FAQs

Package last updated on 06 Oct 2026

Related posts