Socket
Book a DemoInstallSign in
Socket

@borderless/defer

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@borderless/defer

Tiny, type-safe, JavaScript-native `defer` implementation.

latest
Source
npmnpm
Version
2.0.1
Version published
Maintainers
1
Created
Source

Defer

Tiny, type-safe, JavaScript-native defer implementation.

Why? It's helpful to have statements that can automatically execute when a function has completed. For example, to close a file descriptor or clear state.

Installation

npm install @borderless/defer --save

Usage

import { defer, deferSync } from "@borderless/defer";

let i = 0;

const fn = defer(async function* () {
  const result = await doSomethingAsync();

  yield () => {
    i++;
    expect(i).toEqual(1);
  };

  expect(i).toEqual(0);

  return result;
});

await fn(); // `i == 1`.

If you're working with synchronous functions, you can use deferSync instead.

License

MIT

Keywords

defer

FAQs

Package last updated on 12 Dec 2023

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