Skip to content

Latest commit

 

History

History
68 lines (56 loc) · 1.46 KB

usecase-is-already-released.md

File metadata and controls

68 lines (56 loc) · 1.46 KB

UseCase is already released

There are a couple of likely reasons this warning could be appearing:

  • When child use-case is completed after parent use-case did completed

Bad:

        P: Parent UseCase
        C: Child UseCase

                        P fin.   C fin.
        |---------------|          |
        P    |                     |
             C---------------------|
                              |
                          C call dispatch()
class ChildUseCase extends UseCase {
    execute() {
        this.dispatch({ type: "ChildUseCase" });
    }
}
class ParentUseCase extends UseCase {
    execute() {
        // ChildUseCase is independent from Parent
        // But, ChildUseCase is executed from Parent
        // This is programming error
        setTimeout(() => {
            this.context.useCase(new ChildUseCase()).execute();
        }, 16);
        return Promise.resolve();
    }
}

Good:

        P: Parent UseCase
        C: Child UseCase

                       C fin.       P fin.
        |---------------|------------|
        P    |          |
             C----------
                   |
               C call dispatch()    

class ChildUseCase extends UseCase {
    execute() {
        this.dispatch({ type: "ChildUseCase" });
    }
}
class ParentUseCase extends UseCase {
    execute() {
        // Parent wait for Child is completed
        return this.context.useCase(new ChildUseCase()).execute();
    }
}