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

Function clear

packages/effect/src/TxQueue.ts:1309–1325  ·  view source on GitHub ↗
(self: TxEnqueue<A, E>)

Source from the content-addressed store, hash-verified

1307 * @since 4.0.0
1308 */
1309export const clear = <A, E>(self: TxEnqueue<A, E>): Effect.Effect<Array<A>, ExcludeDone<E>> =>
1310 Effect.gen(function*() {
1311 const state = yield* TxRef.get(self.stateRef)
1312 if (state._tag === "Done") {
1313 // Return empty array only for halt causes (like Cause.Done)
1314 if (isDoneCause(state.cause)) {
1315 return []
1316 }
1317 return yield* Effect.failCause(state.cause)
1318 }
1319 const chunk = yield* TxChunk.get(self.items)
1320 yield* TxChunk.set(self.items, Chunk.empty())
1321 if (state._tag === "Closing") {
1322 yield* TxRef.set(self.stateRef, { _tag: "Done", cause: state.cause })
1323 }
1324 return Chunk.toArray(chunk)
1325 }).pipe(Effect.tx)
1326
1327/**
1328 * Shuts down the queue immediately by clearing all items and interrupting it (legacy compatibility).

Callers 1

shutdownFunction · 0.70

Calls 5

isDoneCauseFunction · 0.90
toArrayMethod · 0.80
pipeMethod · 0.65
getMethod · 0.65
setMethod · 0.65

Tested by

no test coverage detected