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

@creditkarma/async-hooks

Package Overview
Dependencies
Maintainers
5
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@creditkarma/async-hooks

An Async Hooks polyfill for Node less than 8, written in TypeScript.

  • 0.0.5
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
4
decreased by-71.43%
Maintainers
5
Weekly downloads
 
Created
Source

Async Hooks

An Async Hooks polyfill for Node < 8, written in TypeScript.

The idea is to provide an interface identical to the native Async Hooks implementation in older versions of Node. If you import the library in Node 8+ it will return the native Async Hooks, otherwise it will return the polyfill.

The docs for Async Hooks here.

This implementation is based largely on the work of Andreas Madsen

Install

$ npm install --save @creditkarma/async-hooks

Usage

createHook

Creates a new AsyncHook object with the supplied callbacks

import * as AsyncHooks from '@creditkarma/async-hooks'

AsyncHooks.createHook({
    init(asyncId: number, type: string, triggerAsyncId: number, resource: object): void {
        // A new async resouce was created
    },
    before(asyncId: number): void {
        // The callback for async resource will be called
    },
    after(asyncId: number): void {
        // The callback for async resource was called
    },
    destroy(asyncId: number): void {
        // The async resource will be garbage collected
    }
}).enable()

In the native implementation of Async Hooks the resource received by the init method is the async object that was created. In the polyfill this resource is likely to not useful and is here for completeness. Usually this will be an empty wrapper object.

executionAsyncId

Returns the unique ID of the currently executing async context.

import * as AsyncHooks from '@creditkarma/async-hooks'

const currentAsyncId: number = AsyncHooks.executionAsyncId()

triggerAsyncId

Returns the unique ID of the parent context for the currently executing async context.

import * as AsyncHooks from '@creditkarma/async-hooks'

const parentAsyncId: number = AsyncHooks.triggerAsyncId()

Keywords

FAQs

Package last updated on 09 May 2018

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