reset

open suspend override fun reset(): Boolean(source)

Resets every module to its initial state and recreates every logic instance.

A reset runs in order. Every coroutine the store launched for the current generation is cancelled and joined, bounded by a timeout after which a warning is logged and the reset continues without the stragglers. The dispatch pipeline then, in one ordered step, calls ModuleLogic.beforeReset on each logic instance, swaps state and logic, and drops every action that was queued before the reset with DispatchResult.Dropped.

The coroutine that awaits this call survives the reset, so a logic method can continue afterwards against the fresh store. Every other coroutine of the old generation is cancelled. Calling this from inside middleware throws, because the pipeline that would complete the reset is busy running that middleware. Use resetAsync there.

Only one reset can execute at a time. A call made while another reset is in progress returns false immediately. An exception thrown by ModuleLogic.beforeReset is rethrown once the reset has completed.

Example:

suspend fun logout() {
storeAccessor.dispatch(AuthAction.LoggingOut(true))
api.logout()
storeAccessor.reset()
}

Return

true if the reset ran, false if one was already in progress

Throws

if the store has not been constructed yet

if called from inside the dispatch pipeline