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

create-async-flag

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

create-async-flag

Simple promise utility for separate, but dependent control flow.

  • 0.1.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
938
decreased by-5.92%
Maintainers
1
Weekly downloads
 
Created
Source

create-async-flag

Simple promise utility for separate, but dependent control flow. See example here.

API

createAsyncFlag()

Creates a flag that can be set, unset, and wait upon.

import createAsyncFlag from 'create-async-flag';

const flag = createAsyncFlag();

[flag].wait()

Creates a promise that will only resolve once set, or resolve immediatly if already set.

const flag = createAsyncFlag();

async function run() {
  // ...
  await flag.wait(); // execution will hault until flag is `set`
  // ...
}

[flag].set()

Marks the flag to be immediatly resolved, and to resolve any currently waiting promises.

const flag = createAsyncFlag();

function log() {
  flag.wait().then(() => console.log('one'));
  flag.set();
  flag.wait().then(() => console.log('two'));
}

log(); // => 'one'
       // => 'two'

[flag].unset()

Marks a flag to wait until set is called again.

const flag = createAsyncFlag();

async function start() {
  flag.unset();
  await flag.wait();
  return; // will never return, unless `set` is called
}
[flag].isSet()

Returns the current state of the flag.

const flag = createAsyncFlag();

flag.isSet(); // => false
flag.set();
flag.isSet(); // => true

FAQs

Package last updated on 30 Jul 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