Skip to content

Commit 6f4feee

Browse files
committed
Make the sleeps for v3 compat, not v4 compat
1 parent 9ef12ec commit 6f4feee

File tree

1 file changed

+9
-21
lines changed

1 file changed

+9
-21
lines changed

stream-helpers/for-each.test.ts

Lines changed: 9 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { createChannel, sleep, spawn, withResolvers } from "effection";
1+
import { createChannel, sleep, spawn } from "effection";
22
import { describe, it } from "@effectionx/bdd";
33
import { expect } from "@std/expect";
44

@@ -11,44 +11,32 @@ describe("forEach", () => {
1111
const stream = createChannel<number, void>();
1212
const processedItems: number[] = [];
1313

14-
const { resolve, operation } = withResolvers<void>();
15-
16-
yield* spawn(() =>
17-
forEach(function* (item: number) {
18-
processedItems.push(item);
19-
}, stream)
20-
);
21-
2214
yield* spawn(function* () {
23-
yield* sleep(1);
15+
yield* sleep(0);
2416
yield* stream.send(1);
2517
yield* stream.send(2);
2618
yield* stream.send(3);
27-
28-
resolve();
19+
yield* stream.close();
2920
});
3021

31-
yield* operation;
22+
yield* forEach(function* (item: number) {
23+
processedItems.push(item);
24+
}, stream);
25+
3226
expect(processedItems).toEqual([1, 2, 3]);
3327
});
3428

3529
it("should return the close value of the stream", function* () {
3630
const stream = createChannel<string, number>();
3731

38-
const result = yield* spawn(() =>
39-
forEach(function* () {
40-
// Just process the item
41-
}, stream)
42-
);
43-
4432
yield* spawn(function* () {
45-
yield* sleep(1);
33+
yield* sleep(0);
4634
yield* stream.send("hello");
4735
yield* stream.send("world");
4836
yield* stream.close(42); // Close with value 42
4937
});
5038

51-
const closeValue = yield* result;
39+
const closeValue = yield* forEach(function* () {}, stream);
5240
expect(closeValue).toBe(42);
5341
});
5442
});

0 commit comments

Comments
 (0)