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

async-flag

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

async-flag

Promise based flag for asynchronous condition

latest
Source
npmnpm
Version
0.0.1
Version published
Maintainers
1
Created
Source

async-flag

Promise based flag for asynchronous condition, for javascript/Nodejs

npm i async-flag

Basic

const AsyncFlag = require('async-flag')
let flag = new AsyncFlag()

//Set the flag somewhere else
setTimeout(() => flag.set('hello'), 10)

//wait for the flag
let result = await flag.get() //result will be 'hello'

Error case

let flag = new AsyncFlag('my-conditiopn')

//Set the error somewhere else
setTimeout(() => flag.error('something wrong'), 10)

flag.get().catch(console.error) //prints 'something wrong'

Timeout

let flag = new AsyncFlag('myFlag')
setTimeout(() => flag.set('hello'), 500)

flag.get(10).catch(console.log)		//expected timeout, prints: "AsyncFlag timeout: myFlag"
flag.get(100).catch(console.log)	//expected timeout, prints: "AsyncFlag timeout: myFlag"
flag.get(1000).then(console.log).catch(console.error)	//expected resolve, prints "hello"
flag.get(1000).then(console.log).catch(console.error)	//expected resolve, prints "hello"

Reset

let flag = new AsyncFlag()
flag.set('hello')
assert('hello' === await flag.get())
flag.reset()  //reset the promise.
flag.set('hello3')
assert('hello3' === await flag.get())

Keywords

async

FAQs

Package last updated on 24 Oct 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