(
fiberId: FiberId.FiberId,
stm: STM.STM<A, E, R>,
state: { value: STMState.STMState<A, E> },
env: Context.Context<R>,
scheduler: Scheduler.Scheduler,
priority: number
)
| 236 | |
| 237 | /** @internal */ |
| 238 | const tryCommit = <A, E, R>( |
| 239 | fiberId: FiberId.FiberId, |
| 240 | stm: STM.STM<A, E, R>, |
| 241 | state: { value: STMState.STMState<A, E> }, |
| 242 | env: Context.Context<R>, |
| 243 | scheduler: Scheduler.Scheduler, |
| 244 | priority: number |
| 245 | ): TryCommit.TryCommit<A, E> => { |
| 246 | const journal: Journal.Journal = new Map() |
| 247 | const tExit = new STMDriver(stm, journal, fiberId, env).run() |
| 248 | const analysis = Journal.analyzeJournal(journal) |
| 249 | |
| 250 | if (analysis === Journal.JournalAnalysisReadWrite) { |
| 251 | Journal.commitJournal(journal) |
| 252 | } else if (analysis === Journal.JournalAnalysisInvalid) { |
| 253 | throw new Error( |
| 254 | "BUG: STM.TryCommit.tryCommit - please report an issue at https://github.com/Effect-TS/effect/issues" |
| 255 | ) |
| 256 | } |
| 257 | |
| 258 | switch (tExit._tag) { |
| 259 | case TExitOpCodes.OP_SUCCEED: { |
| 260 | state.value = STMState.fromTExit(tExit) |
| 261 | return completeTodos(Exit.succeed(tExit.value), journal, scheduler, priority) |
| 262 | } |
| 263 | case TExitOpCodes.OP_FAIL: { |
| 264 | state.value = STMState.fromTExit(tExit) |
| 265 | const cause = Cause.fail(tExit.error) |
| 266 | return completeTodos( |
| 267 | Exit.failCause(cause), |
| 268 | journal, |
| 269 | scheduler, |
| 270 | priority |
| 271 | ) |
| 272 | } |
| 273 | case TExitOpCodes.OP_DIE: { |
| 274 | state.value = STMState.fromTExit(tExit) |
| 275 | const cause = Cause.die(tExit.defect) |
| 276 | return completeTodos( |
| 277 | Exit.failCause(cause), |
| 278 | journal, |
| 279 | scheduler, |
| 280 | priority |
| 281 | ) |
| 282 | } |
| 283 | case TExitOpCodes.OP_INTERRUPT: { |
| 284 | state.value = STMState.fromTExit(tExit) |
| 285 | const cause = Cause.interrupt(fiberId) |
| 286 | return completeTodos( |
| 287 | Exit.failCause(cause), |
| 288 | journal, |
| 289 | scheduler, |
| 290 | priority |
| 291 | ) |
| 292 | } |
| 293 | case TExitOpCodes.OP_RETRY: { |
| 294 | return TryCommit.suspend(journal) |
| 295 | } |
no test coverage detected