githubEdit

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 examplearrow-up-right

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 examplearrow-up-right

Subtilities of evt.waitFor(...)

Playgroundarrow-up-right

Last updated

Was this helpful?