| 1307 | * @since 4.0.0 |
| 1308 | */ |
| 1309 | export 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). |