in MobiusCore/Source/EffectHandlers/EffectExecutor.swift [41:63]
func handle(_ effect: Effect) {
let id: Int64 = lock.synchronized {
nextID += 1
return nextID
}
let callback = EffectCallback(
// Any events produced as a result of handling the effect will be sent to this class's `output` consumer,
// unless it has already been disposed.
onSend: { [weak self] event in self?.output?(event) },
// Once an effect has been handled, remove the reference to its callback and disposable.
onEnd: { [weak self] in self?.delete(id: id) }
)
let disposable = handleEffect(effect, callback)
store(id: id, callback: callback, disposable: disposable)
// We cannot know if `callback.end()` was called before `self.store(..)`. This check ensures that if
// the callback was ended early, the reference to it will be deleted.
if callback.ended {
delete(id: id)
}
}