MCPcopy Create free account
hub / github.com/Effect-TS/effect / loop

Function loop

packages/effect/src/cluster/SqlMessageStorage.ts:373–390  ·  view source on GitHub ↗
(attempt: number)

Source from the content-addressed store, hash-verified

371 // deleteProcessed can delete the existing row before it is read, so insert
372 // again rather than report a save that stored nothing
373 const loop = (attempt: number): Effect.Effect<ReadonlyArray<Row>, SqlError> =>
374 Effect.flatMap(
375 insert(row, message_id),
376 (inserted) =>
377 inserted ? Effect.succeed([]) : Effect.flatMap(selectByMessageId(message_id, lock), (rows) => {
378 if (rows.length > 0) return Effect.succeed(rows)
379 if (attempt < maxInsertAttempts) return loop(attempt + 1)
380 return Effect.fail(
381 new SqlError({
382 reason: new UnknownError({
383 cause: undefined,
384 message: `Message ${message_id} conflicted with a row that was deleted before it could be read`,
385 operation: "saveEnvelope"
386 })
387 })
388 )
389 })
390 )
391 return loop(1)
392 }
393

Callers 1

insertUnlessExistsFunction · 0.70

Calls 4

selectByMessageIdFunction · 0.85
failMethod · 0.65
insertFunction · 0.50
succeedMethod · 0.45

Tested by

no test coverage detected