0.1.0 • Published 3 years ago

@evocount/signal v0.1.0

Weekly downloads
-
License
MIT
Repository
github
Last release
3 years ago

Signal

Build Status

A small library to manage asynchronous tasks using coroutines.

Usage

npm i --save @evocount/signal

Example

A signal lets you wait at a certain position of your code until the notify method is called.

import Signal from "@evocount/signal"

(async () => {
	const signal = new Signal

	//call signal in 1s
	setTimeout(() => signal.notify(), 1000)

	//wait until notify is called
	await signal.wait()
})()

This can be used to send a cancel signal to a running loop.

E.g. Let a loop run for 1s.

import Signal from "@evocount/signal"

(async () => {
	const signal = new Signal

	//notify the signal after 1s
	setTimeout(() => signal.notify(), 1000)

	await signal.repeat(async (cancel: Signal) => {
		//repeat this function until the signal is notified
	})
})()

You can also make this dependent on a shutdown event.

0.1.0

3 years ago

0.0.7

3 years ago

0.0.6

3 years ago

0.0.5

3 years ago

0.0.4

3 years ago

0.0.3

3 years ago

0.0.0

3 years ago