New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

@mrubiosan/context

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

@mrubiosan/context

Context cancellation for long lived functions

latest
Source
npmnpm
Version
0.1.1
Version published
Maintainers
1
Created
Source

Context

A context governs the lifespan of a task. It can be canceled at will, or automatically after a given deadline. The task and any subtasks are notified when the context ends, allowing for clean shutdowns.

This is a subset of the Go context package adapted to JavaScript and Promises.

Usage Example

import { RootContext } from '@mrubiosan/context'

function someAsyncOperation(ms: number): Promise<void> {
  return new Promise(resolve => {
    setTimeout(resolve, ms).unref()
  })
}

async function main() {
  const [ctx, cancel] = RootContext.withTimeout(1500)
  try {
    await ctx.race(someAsyncOperation(2000))
  } finally {
    cancel()
  }
}

main()

Keywords

go

FAQs

Package last updated on 07 Oct 2022

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