1- import { createChannel , sleep , spawn , withResolvers } from "effection" ;
1+ import { createChannel , sleep , spawn } from "effection" ;
22import { describe , it } from "@effectionx/bdd" ;
33import { expect } from "@std/expect" ;
44
@@ -11,44 +11,33 @@ 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- ) ;
4332
4433 yield * spawn ( function * ( ) {
45- yield * sleep ( 1 ) ;
34+ yield * sleep ( 0 ) ;
4635 yield * stream . send ( "hello" ) ;
4736 yield * stream . send ( "world" ) ;
4837 yield * stream . close ( 42 ) ; // Close with value 42
4938 } ) ;
5039
51- const closeValue = yield * result ;
40+ const closeValue = yield * forEach ( function * ( ) { } , stream ) ;
5241 expect ( closeValue ) . toBe ( 42 ) ;
5342 } ) ;
5443} ) ;
0 commit comments