1212use Innmind \OperatingSystem \OperatingSystem ;
1313use Innmind \Url \Path ;
1414use Innmind \Immutable \{
15+ Attempt ,
1516 Sequence ,
1617 Predicate \Instance ,
1718};
@@ -22,6 +23,7 @@ final class Loop
2223 private Sequence $ agents ;
2324 private Activities $ activities ;
2425 private Path $ project ;
26+ private bool $ started = false ;
2527
2628 /**
2729 * @param Sequence<Agent> $agents
@@ -37,22 +39,22 @@ public function __construct(
3739 }
3840
3941 /**
40- * @param array{ Console, boolean} $carry
41- * @param Continuation<array{ Console, boolean} > $continuation
42+ * @param Attempt< Console> $console
43+ * @param Continuation<Attempt< Console> > $continuation
4244 *
43- * @return Continuation<array{ Console, boolean} >
45+ * @return Continuation<Attempt< Console> >
4446 */
4547 public function __invoke (
46- array $ carry ,
48+ Attempt $ console ,
4749 OperatingSystem $ os ,
4850 Continuation $ continuation ,
4951 ): Continuation {
50- [$ console , $ started ] = $ carry ;
52+ if (!$ this ->started ) {
53+ $ this ->started = true ;
5154
52- if (!$ started ) {
5355 return $ continuation
5456 ->schedule ($ this ->agents ->map ($ this ->buildTask (...)))
55- ->carryWith ([ $ console, true ] );
57+ ->carryWith ($ console );
5658 }
5759
5860 $ continuation = $ continuation ->schedule (
@@ -62,12 +64,14 @@ public function __invoke(
6264 ->map ($ this ->buildTask (...)),
6365 );
6466
65- $ console = ($ this ->activities )(
66- $ console ,
67- $ os ,
67+ return $ console ->match (
68+ fn ($ console ) => $ continuation ->carryWith (
69+ ($ this ->activities )($ console , $ os ),
70+ ),
71+ static fn ($ e ) => $ continuation
72+ ->carryWith (Attempt::error ($ e ))
73+ ->terminate (),
6874 );
69-
70- return $ continuation ->carryWith ([$ console , $ started ]);
7175 }
7276
7377 /**
0 commit comments