When forking a Workflow, the didComplete() function is called each time one of the forks completes. I understand that this is happening because each fork needs to call .commit(), which adds a subscription, but intuitively I would expect didComplete() to only be called once per Workflow after all branches had completed.
A basic test case of this:
func test_fork_verifySingleCompletion() {
let workflow = TestWorkflow()
let emptyObservable = Observable.just(((), ()))
let rootStep = workflow
.onStep { _ -> Observable<((), ())> in
return emptyObservable
}
let firstFork: Step<(), (), ()>? = rootStep.asObservable().fork(workflow)
_ = firstFork?
.onStep { (_, _) -> Observable<((), ())> in
return Observable.just(((), ()))
}
.commit()
let secondFork: Step<(), (), ()>? = rootStep.asObservable().fork(workflow)
_ = secondFork?
.onStep { (_, _) -> Observable<((), ())> in
return Observable.just(((), ()))
}
.commit()
XCTAssertEqual(0, workflow.completeCallCount)
_ = workflow.subscribe(())
XCTAssertEqual(1, workflow.completeCallCount) // XCTAssertEqual failed: ("1") is not equal to ("2")
}
When forking a
Workflow, thedidComplete()function is called each time one of the forks completes. I understand that this is happening because each fork needs to call.commit(), which adds a subscription, but intuitively I would expectdidComplete()to only be called once perWorkflowafter all branches had completed.A basic test case of this: