( self: STM.STM<A, E, R>, onDone: (exit: Exit.Exit<A, E>) => unknown, onInterrupt: LazyArg<unknown> )
| 190 | |
| 191 | /** @internal */ |
| 192 | export const unsafeAtomically = <A, E, R>( |
| 193 | self: STM.STM<A, E, R>, |
| 194 | onDone: (exit: Exit.Exit<A, E>) => unknown, |
| 195 | onInterrupt: LazyArg<unknown> |
| 196 | ): Effect.Effect<A, E, R> => |
| 197 | withFiberRuntime((state) => { |
| 198 | const fiberId = state.id() |
| 199 | const env = state.getFiberRef(FiberRef.currentContext) as Context.Context<R> |
| 200 | const scheduler = state.getFiberRef(FiberRef.currentScheduler) |
| 201 | const priority = state.getFiberRef(FiberRef.currentSchedulingPriority) |
| 202 | const commitResult = tryCommitSync(fiberId, self, env, scheduler, priority) |
| 203 | switch (commitResult._tag) { |
| 204 | case TryCommitOpCodes.OP_DONE: { |
| 205 | onDone(commitResult.exit) |
| 206 | return commitResult.exit |
| 207 | } |
| 208 | case TryCommitOpCodes.OP_SUSPEND: { |
| 209 | const txnId = TxnId.make() |
| 210 | const state: { value: STMState.STMState<A, E> } = { value: STMState.running } |
| 211 | const effect = Effect.async( |
| 212 | (k: (effect: Effect.Effect<A, E, R>) => unknown): void => |
| 213 | tryCommitAsync(fiberId, self, txnId, state, env, scheduler, priority, k) |
| 214 | ) |
| 215 | return Effect.uninterruptibleMask((restore) => |
| 216 | pipe( |
| 217 | restore(effect), |
| 218 | Effect.catchAllCause((cause) => { |
| 219 | let currentState = state.value |
| 220 | if (STMState.isRunning(currentState)) { |
| 221 | state.value = STMState.interrupted |
| 222 | } |
| 223 | currentState = state.value |
| 224 | if (STMState.isDone(currentState)) { |
| 225 | onDone(currentState.exit) |
| 226 | return currentState.exit |
| 227 | } |
| 228 | onInterrupt() |
| 229 | return Effect.failCause(cause) |
| 230 | }) |
| 231 | ) |
| 232 | ) |
| 233 | } |
| 234 | } |
| 235 | }) |
| 236 | |
| 237 | /** @internal */ |
| 238 | const tryCommit = <A, E, R>( |
no test coverage detected