mercredi 19 août 2015

Pattern to solve multiple callbacks in TypeScript

I am looking for a way to solve this often occurring problem of mine.

Lets say I have a class as the following in TypeScript:

class Example {

    constructor() {
        this.work();
        this.doMoreWork();        
    }

    work() {
        // Work on some more borring async work
    }

    doMoreWork() {
        // Going for some borring async work
    }    

    finishedWorking() {
        // Call me when work() and doMoreWork() is finished
    }
}

I would like to call finishedWorking() when work() and doMoreWork() are done. Does anyone know a good pattern I could use in TypeScript to solve this?

As I know async and await is not an option right now?

Aucun commentaire:

Enregistrer un commentaire