evt.waitFor(...)

Method that returns a promise that will resolve when the next matched event is posted.

Without timeout

By default the promise returned by waitFor will never reject.

import { Evt } from "evt";

const evtText = Evt.create<string>();

setTimeout(()=> evtText.post("Hi!"), 1500);

(async ()=>{

    //waitFor return a promise that will resolve next time 
    //post() is invoked on evtText.
    const text = await evtText.waitFor();

    console.log(text);

})();

Run the example

With timeout

As with attach*, it is possible to set what is the maximum amount of time we are willing to wait for the event before the promise rejects.

Run the example

Subtilities of evt.waitFor(...)

Playground

Last updated