Skip to content

Latest commit

 

History

History

async-autoresetevent

The @esfx/async-autoresetevent package provides the AsyncAutoResetEvent class, an async coordination primitive.

Overview

Installation

npm i @esfx/async-autoresetevent

Usage

import { AsyncAutoResetEvent } from "@esfx/async-autoresetevent";

const event = new AsyncAutoResetEvent();

async function doSomeActivity() {
    while (true) {
        // do some work asynchronously...

        // indicate 'waitForActivity' can resume. Event is immediately reset to
        // the unsignaled state.
        event.set();
    }
}

async function waitForActivity() {
    while (true) {
        // wait for 'doSomeActivity' to set the event...
        await event.wait();

        // do something asynchronous...
    }
}

doSomeActivity();
waitForActivity();

API

You can read more about the API here.