brass-runtime 1.4.3 → 1.4.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1 @@
1
+ function p(n,e,t){return {_tag:"Fold",first:n,onFailure:e,onSuccess:t}}function x(n,e){return p(n,t=>e(t),t=>d(t))}function F(n,e){return p(n,t=>R(e(t)),t=>d(t))}function k(){return y(()=>{})}var d=n=>({_tag:"Succeed",value:n}),R=n=>({_tag:"Fail",error:n}),y=n=>({_tag:"Sync",thunk:n}),_=n=>y(()=>n()),l=n=>({_tag:"Async",register:n});function N(n,e){return E(n,t=>d(e(t)))}function E(n,e){return {_tag:"FlatMap",first:n,andThen:e}}function q(n,e,t){return E(n,r=>(t.addFinalizer(o=>e(r,o)),d(r)))}function D(n){return l(n)}var f=class{queue=[];flushing=false;requested=false;schedule(e,t="anonymous"){if(console.log("[Scheduler.schedule] typeof task =",typeof e,"tag=",t),typeof e!="function"){console.error("[Scheduler.schedule] NON-FUNCTION TASK!",{tag:t,task:e});return}this.queue.push({tag:t,task:e}),this.requestFlush(),console.log("SCHEDULER",{flushing:this.flushing,q:this.queue.length,next:this.queue[0]?.tag,head:this.queue.slice(0,5).map(r=>r.tag)});}requestFlush(){console.log("requestFlush",{flushing:this.flushing,requested:this.requested,q:this.queue.length}),!this.flushing&&(this.requested||(this.requested=true,queueMicrotask(()=>{console.log(">> microtask fired",{flushing:this.flushing,requested:this.requested,q:this.queue.length}),this.flush();})));}flush(){if(console.log("FLUSH enter",{flushing:this.flushing,requested:this.requested,q:this.queue.length}),!this.flushing){this.flushing=true,this.requested=false;try{for(;this.queue.length>0;){let e=this.queue.shift();console.log("[flush] dequeued",{tag:e.tag,typeofTask:typeof e.task});try{console.log("TASK typeof",typeof e.task),e.task();}catch(t){console.error("[flush] task threw",t);}}}finally{this.flushing=false,console.log("FLUSH exit",{requested:this.requested,q:this.queue.length}),this.queue.length>0&&this.requestFlush();}}}},g=new f;var u={CONTINUE:"Continue",SUSPEND:"Suspend",DONE:"Done"},c={QUEUED:"Queued",RUNNING:"Running",SUSPENDED:"Suspended",DONE:"Done"},S=1,A=class{constructor(e,t,r){this.scheduler=r;this.id=S++,this.current=e,this.env=t;}id;closing=null;finishing=false;runState=c.RUNNING;interrupted=false;result=null;joiners=[];current;env;stack=[];fiberFinalizers=[];finalizersDrained=false;addFinalizer(e){this.fiberFinalizers.push(e);}status(){return this.result==null?"Running":this.interrupted?"Interrupted":"Done"}join(e){this.result!=null?e(this.result):this.joiners.push(e);}interrupt(){this.result==null&&(this.interrupted||(this.interrupted=true,this.schedule("interrupt-step")));}schedule(e="step"){console.log("[fiber.schedule]",{fiber:this.id,tag:e,runState:this.runState,schedulerCtor:this.scheduler?.constructor?.name,schedulerScheduleType:typeof this.scheduler?.schedule}),!(this.runState===c.DONE||this.runState===c.QUEUED)&&(this.runState=c.QUEUED,this.scheduler.schedule(()=>{if(console.log("[fiber.task] running",this.id),this.runState===c.DONE)return;switch(this.runState=c.RUNNING,this.step()){case u.CONTINUE:this.schedule("continue");return;case u.SUSPEND:this.runState=c.SUSPENDED;return;case u.DONE:this.runState=c.DONE;return}},`fiber#${this.id}.${e}`));}runFinalizersOnce(e){if(!this.finalizersDrained)for(this.finalizersDrained=true;this.fiberFinalizers.length>0;){let t=this.fiberFinalizers.pop();try{t(e);}catch{}}}notify(e){if(this.result==null&&this.closing==null){this.finishing=true,this.closing=e,this.runFinalizersOnce(e),this.result=e;for(let t of this.joiners)t(e);this.joiners.length=0;}}onSuccess(e){let t=this.stack.pop();if(!t){this.notify({_tag:"Success",value:e});return}this.current=t._tag==="SuccessCont"?t.k(e):t.onSuccess(e);}onFailure(e){for(;this.stack.length>0;){let t=this.stack.pop();if(t._tag==="FoldCont"){this.current=t.onFailure(e);return}}this.notify({_tag:"Failure",error:e});}step(){console.log("[fiber.step] enter",{fiber:this.id,current:this.current?._tag,result:this.result!=null,interrupted:this.interrupted,closing:this.closing!=null,finishing:this.finishing,stack:this.stack.length});let e=u.CONTINUE;if(this.result!=null)return e=u.DONE,e;if(this.interrupted&&this.closing==null)return console.log("[fiber.step] interrupted: failing now",{fiber:this.id}),this.notify({_tag:"Failure",error:{_tag:"Interrupted"}}),e=u.DONE,e;let t=this.current;switch(t._tag){case "Succeed":{console.log("[fiber.step] Succeed",{fiber:this.id}),this.onSuccess(t.value);break}case "Fail":{console.log("[fiber.step] Fail",{fiber:this.id}),this.onFailure(t.error);break}case "Sync":{console.log("[fiber.step] Sync",{fiber:this.id});try{let r=t.thunk(this.env);console.log("[fiber.step] Sync success",{fiber:this.id}),this.onSuccess(r);}catch(r){console.log("[fiber.step] Sync threw",{fiber:this.id,e:r}),this.onFailure(r);}break}case "FlatMap":{console.log("[fiber.step] FlatMap push cont",{fiber:this.id}),this.stack.push({_tag:"SuccessCont",k:t.andThen}),this.current=t.first;break}case "Fold":{console.log("[fiber.step] Fold push cont",{fiber:this.id}),this.stack.push({_tag:"FoldCont",onFailure:t.onFailure,onSuccess:t.onSuccess}),this.current=t.first;break}case "Async":{if(this.finishing)break;let r=false,o=s=>{if(!(this.result!=null||this.closing!=null)){if(this.interrupted){this.onFailure({_tag:"Interrupted"});return}s._tag==="Success"?this.onSuccess(s.value):this.onFailure(s.error),this.schedule("async-resume");}},i=s=>{r||(r=true,this.scheduler.schedule(()=>o(s),`fiber#${this.id}.async-resume`));},a=t.register(this.env,i);typeof a=="function"&&this.addFinalizer(()=>{r=true;try{a();}catch{}}),e=u.SUSPEND;break}}return this.result!=null&&(e=u.DONE),e}};function M(n){return l((e,t)=>{let r=false,o=s=>{r||(r=true,t(s));},i=s=>o({_tag:"Failure",error:s instanceof Error?s:new Error(String(s))}),a=s=>o({_tag:"Success",value:s});try{typeof n=="function"&&n.length>=1?n((s,h)=>s?i(s):a(h)):n().then(a,i);}catch(s){i(s);}})}function b(n,e,t=g){let r=new A(n,e,t);return r.schedule("initial-step"),r}function Q(n,e,t){b(n,e).join(t);}function G(n,e){return new Promise((t,r)=>{b(n,e).join(i=>{let a=i;a._tag==="Success"?t(a.value):r(a.error);});})}function H(n,e){return l((t,r)=>{n(t).then(o=>r({_tag:"Success",value:o})).catch(o=>r({_tag:"Failure",error:e(o)}));})}function L(n){return l((e,t)=>{let r=false,o=i=>{r||(r=true,t(i));};try{n((i,a)=>{o(i?{_tag:"Failure",error:i}:{_tag:"Success",value:a});});}catch(i){o({_tag:"Failure",error:i instanceof Error?i:new Error(String(i))});}})}function $(n){return v((t,r)=>n.length===1?n(r):n(t,r),t=>m(t)?{_tag:"Abort"}:{_tag:"PromiseRejected",reason:t})}function v(n,e){return l((t,r)=>{let o=new AbortController,i=false,a=s=>{i||(i=true,r(s));};try{(n.length===1?n(o.signal):n(t,o.signal)).then(h=>a({_tag:"Success",value:h})).catch(h=>a({_tag:"Failure",error:e(h)}));}catch(s){a({_tag:"Failure",error:e(s)});}return ()=>{i=true,o.abort();}})}var m=n=>typeof n=="object"&&n!==null&&"name"in n&&n.name==="AbortError";export{p as a,x as b,F as c,k as d,d as e,R as f,y as g,_ as h,l as i,N as j,E as k,q as l,D as m,f as n,g as o,A as p,M as q,b as r,Q as s,G as t,H as u,L as v,$ as w,v as x};
@@ -0,0 +1 @@
1
+ 'use strict';function p(n,e,t){return {_tag:"Fold",first:n,onFailure:e,onSuccess:t}}function x(n,e){return p(n,t=>e(t),t=>d(t))}function F(n,e){return p(n,t=>R(e(t)),t=>d(t))}function k(){return y(()=>{})}var d=n=>({_tag:"Succeed",value:n}),R=n=>({_tag:"Fail",error:n}),y=n=>({_tag:"Sync",thunk:n}),_=n=>y(()=>n()),l=n=>({_tag:"Async",register:n});function N(n,e){return E(n,t=>d(e(t)))}function E(n,e){return {_tag:"FlatMap",first:n,andThen:e}}function q(n,e,t){return E(n,r=>(t.addFinalizer(o=>e(r,o)),d(r)))}function D(n){return l(n)}var f=class{queue=[];flushing=false;requested=false;schedule(e,t="anonymous"){if(console.log("[Scheduler.schedule] typeof task =",typeof e,"tag=",t),typeof e!="function"){console.error("[Scheduler.schedule] NON-FUNCTION TASK!",{tag:t,task:e});return}this.queue.push({tag:t,task:e}),this.requestFlush(),console.log("SCHEDULER",{flushing:this.flushing,q:this.queue.length,next:this.queue[0]?.tag,head:this.queue.slice(0,5).map(r=>r.tag)});}requestFlush(){console.log("requestFlush",{flushing:this.flushing,requested:this.requested,q:this.queue.length}),!this.flushing&&(this.requested||(this.requested=true,queueMicrotask(()=>{console.log(">> microtask fired",{flushing:this.flushing,requested:this.requested,q:this.queue.length}),this.flush();})));}flush(){if(console.log("FLUSH enter",{flushing:this.flushing,requested:this.requested,q:this.queue.length}),!this.flushing){this.flushing=true,this.requested=false;try{for(;this.queue.length>0;){let e=this.queue.shift();console.log("[flush] dequeued",{tag:e.tag,typeofTask:typeof e.task});try{console.log("TASK typeof",typeof e.task),e.task();}catch(t){console.error("[flush] task threw",t);}}}finally{this.flushing=false,console.log("FLUSH exit",{requested:this.requested,q:this.queue.length}),this.queue.length>0&&this.requestFlush();}}}},g=new f;var u={CONTINUE:"Continue",SUSPEND:"Suspend",DONE:"Done"},c={QUEUED:"Queued",RUNNING:"Running",SUSPENDED:"Suspended",DONE:"Done"},S=1,A=class{constructor(e,t,r){this.scheduler=r;this.id=S++,this.current=e,this.env=t;}id;closing=null;finishing=false;runState=c.RUNNING;interrupted=false;result=null;joiners=[];current;env;stack=[];fiberFinalizers=[];finalizersDrained=false;addFinalizer(e){this.fiberFinalizers.push(e);}status(){return this.result==null?"Running":this.interrupted?"Interrupted":"Done"}join(e){this.result!=null?e(this.result):this.joiners.push(e);}interrupt(){this.result==null&&(this.interrupted||(this.interrupted=true,this.schedule("interrupt-step")));}schedule(e="step"){console.log("[fiber.schedule]",{fiber:this.id,tag:e,runState:this.runState,schedulerCtor:this.scheduler?.constructor?.name,schedulerScheduleType:typeof this.scheduler?.schedule}),!(this.runState===c.DONE||this.runState===c.QUEUED)&&(this.runState=c.QUEUED,this.scheduler.schedule(()=>{if(console.log("[fiber.task] running",this.id),this.runState===c.DONE)return;switch(this.runState=c.RUNNING,this.step()){case u.CONTINUE:this.schedule("continue");return;case u.SUSPEND:this.runState=c.SUSPENDED;return;case u.DONE:this.runState=c.DONE;return}},`fiber#${this.id}.${e}`));}runFinalizersOnce(e){if(!this.finalizersDrained)for(this.finalizersDrained=true;this.fiberFinalizers.length>0;){let t=this.fiberFinalizers.pop();try{t(e);}catch{}}}notify(e){if(this.result==null&&this.closing==null){this.finishing=true,this.closing=e,this.runFinalizersOnce(e),this.result=e;for(let t of this.joiners)t(e);this.joiners.length=0;}}onSuccess(e){let t=this.stack.pop();if(!t){this.notify({_tag:"Success",value:e});return}this.current=t._tag==="SuccessCont"?t.k(e):t.onSuccess(e);}onFailure(e){for(;this.stack.length>0;){let t=this.stack.pop();if(t._tag==="FoldCont"){this.current=t.onFailure(e);return}}this.notify({_tag:"Failure",error:e});}step(){console.log("[fiber.step] enter",{fiber:this.id,current:this.current?._tag,result:this.result!=null,interrupted:this.interrupted,closing:this.closing!=null,finishing:this.finishing,stack:this.stack.length});let e=u.CONTINUE;if(this.result!=null)return e=u.DONE,e;if(this.interrupted&&this.closing==null)return console.log("[fiber.step] interrupted: failing now",{fiber:this.id}),this.notify({_tag:"Failure",error:{_tag:"Interrupted"}}),e=u.DONE,e;let t=this.current;switch(t._tag){case "Succeed":{console.log("[fiber.step] Succeed",{fiber:this.id}),this.onSuccess(t.value);break}case "Fail":{console.log("[fiber.step] Fail",{fiber:this.id}),this.onFailure(t.error);break}case "Sync":{console.log("[fiber.step] Sync",{fiber:this.id});try{let r=t.thunk(this.env);console.log("[fiber.step] Sync success",{fiber:this.id}),this.onSuccess(r);}catch(r){console.log("[fiber.step] Sync threw",{fiber:this.id,e:r}),this.onFailure(r);}break}case "FlatMap":{console.log("[fiber.step] FlatMap push cont",{fiber:this.id}),this.stack.push({_tag:"SuccessCont",k:t.andThen}),this.current=t.first;break}case "Fold":{console.log("[fiber.step] Fold push cont",{fiber:this.id}),this.stack.push({_tag:"FoldCont",onFailure:t.onFailure,onSuccess:t.onSuccess}),this.current=t.first;break}case "Async":{if(this.finishing)break;let r=false,o=s=>{if(!(this.result!=null||this.closing!=null)){if(this.interrupted){this.onFailure({_tag:"Interrupted"});return}s._tag==="Success"?this.onSuccess(s.value):this.onFailure(s.error),this.schedule("async-resume");}},i=s=>{r||(r=true,this.scheduler.schedule(()=>o(s),`fiber#${this.id}.async-resume`));},a=t.register(this.env,i);typeof a=="function"&&this.addFinalizer(()=>{r=true;try{a();}catch{}}),e=u.SUSPEND;break}}return this.result!=null&&(e=u.DONE),e}};function M(n){return l((e,t)=>{let r=false,o=s=>{r||(r=true,t(s));},i=s=>o({_tag:"Failure",error:s instanceof Error?s:new Error(String(s))}),a=s=>o({_tag:"Success",value:s});try{typeof n=="function"&&n.length>=1?n((s,h)=>s?i(s):a(h)):n().then(a,i);}catch(s){i(s);}})}function b(n,e,t=g){let r=new A(n,e,t);return r.schedule("initial-step"),r}function Q(n,e,t){b(n,e).join(t);}function G(n,e){return new Promise((t,r)=>{b(n,e).join(i=>{let a=i;a._tag==="Success"?t(a.value):r(a.error);});})}function H(n,e){return l((t,r)=>{n(t).then(o=>r({_tag:"Success",value:o})).catch(o=>r({_tag:"Failure",error:e(o)}));})}function L(n){return l((e,t)=>{let r=false,o=i=>{r||(r=true,t(i));};try{n((i,a)=>{o(i?{_tag:"Failure",error:i}:{_tag:"Success",value:a});});}catch(i){o({_tag:"Failure",error:i instanceof Error?i:new Error(String(i))});}})}function $(n){return v((t,r)=>n.length===1?n(r):n(t,r),t=>m(t)?{_tag:"Abort"}:{_tag:"PromiseRejected",reason:t})}function v(n,e){return l((t,r)=>{let o=new AbortController,i=false,a=s=>{i||(i=true,r(s));};try{(n.length===1?n(o.signal):n(t,o.signal)).then(h=>a({_tag:"Success",value:h})).catch(h=>a({_tag:"Failure",error:e(h)}));}catch(s){a({_tag:"Failure",error:e(s)});}return ()=>{i=true,o.abort();}})}var m=n=>typeof n=="object"&&n!==null&&"name"in n&&n.name==="AbortError";exports.a=p;exports.b=x;exports.c=F;exports.d=k;exports.e=d;exports.f=R;exports.g=y;exports.h=_;exports.i=l;exports.j=N;exports.k=E;exports.l=q;exports.m=D;exports.n=f;exports.o=g;exports.p=A;exports.q=M;exports.r=b;exports.s=Q;exports.t=G;exports.u=H;exports.v=L;exports.w=$;exports.x=v;
@@ -19,11 +19,23 @@ declare function makeCancelToken(): CancelToken & {
19
19
  */
20
20
  declare function linkAbortController(token: CancelToken, ac: AbortController): Canceler;
21
21
 
22
+ type Task = () => void;
23
+ declare class Scheduler {
24
+ private queue;
25
+ private flushing;
26
+ private requested;
27
+ schedule(task: Task, tag?: string): void;
28
+ private requestFlush;
29
+ private flush;
30
+ }
31
+ declare const globalScheduler: Scheduler;
32
+
22
33
  type FiberId = number;
23
- type FiberStatus = "Running" | "Done" | "Interrupted";
24
34
  type Interrupted = {
25
35
  readonly _tag: "Interrupted";
26
36
  };
37
+ type FiberStatus = "Running" | "Done" | "Interrupted";
38
+ type StepDecision = "Continue" | "Suspend" | "Done";
27
39
  type Fiber<E, A> = {
28
40
  readonly id: FiberId;
29
41
  readonly status: () => FiberStatus;
@@ -31,12 +43,32 @@ type Fiber<E, A> = {
31
43
  readonly interrupt: () => void;
32
44
  readonly addFinalizer: (f: (exit: Exit<E | Interrupted, A>) => void) => void;
33
45
  };
34
- type BrassError = {
35
- _tag: "Abort";
36
- } | {
37
- _tag: "PromiseRejected";
38
- reason: unknown;
39
- };
46
+ declare class RuntimeFiber<R, E, A> implements Fiber<E, A> {
47
+ private readonly scheduler;
48
+ readonly id: FiberId;
49
+ private closing;
50
+ private finishing;
51
+ private runState;
52
+ private interrupted;
53
+ private result;
54
+ private readonly joiners;
55
+ private current;
56
+ private readonly env;
57
+ private readonly stack;
58
+ private readonly fiberFinalizers;
59
+ private finalizersDrained;
60
+ constructor(effect: Async<R, E, A>, env: R, scheduler: Scheduler);
61
+ addFinalizer(f: (exit: Exit<E | Interrupted, A>) => void): void;
62
+ status(): FiberStatus;
63
+ join(cb: (exit: Exit<E | Interrupted, A>) => void): void;
64
+ interrupt(): void;
65
+ schedule(tag?: string): void;
66
+ private runFinalizersOnce;
67
+ private notify;
68
+ private onSuccess;
69
+ private onFailure;
70
+ step(): StepDecision;
71
+ }
40
72
 
41
73
  type ScopeId = number;
42
74
  declare class Scope<R> {
@@ -53,7 +85,6 @@ declare class Scope<R> {
53
85
  subScope(): Scope<R>;
54
86
  /** fork en este scope */
55
87
  fork<E, A>(eff: Async<R, E, A>, env: R): Fiber<E | Interrupted, A>;
56
- /** Cierre estructurado */
57
88
  close(exit?: Exit<any, any>): void;
58
89
  isClosed(): boolean;
59
90
  }
@@ -63,7 +94,6 @@ declare class Scope<R> {
63
94
  */
64
95
  declare function withScope<R, A>(body: (scope: Scope<R>) => A): A;
65
96
 
66
- type NodeCallback<A> = (err: Error | null, result: A) => void;
67
97
  type Async<R, E, A> = {
68
98
  _tag: "Succeed";
69
99
  value: A;
@@ -89,8 +119,6 @@ type Async<R, E, A> = {
89
119
  declare function asyncFold<R, E, A, B>(fa: Async<R, E, A>, onFailure: (e: E) => Async<R, E, B>, onSuccess: (a: A) => Async<R, E, B>): Async<R, E, B>;
90
120
  declare function asyncCatchAll<R, E, A, R2, E2, B>(fa: Async<R, E, A>, handler: (e: E) => Async<R2, E2, B>): Async<R & R2, E2, A | B>;
91
121
  declare function asyncMapError<R, E, E2, A>(fa: Async<R, E, A>, f: (e: E) => E2): Async<R, E2, A>;
92
- declare function from<A>(f: (cb: NodeCallback<A>) => void): Async<{}, Error, A>;
93
- declare function from<A>(thunk: () => Promise<A>): Async<{}, Error, A>;
94
122
  declare function unit(): Async<unknown, unknown, undefined>;
95
123
  declare const asyncSucceed: <A>(value: A) => Async<unknown, never, A>;
96
124
  declare const asyncFail: <E>(error: E) => Async<unknown, E, never>;
@@ -99,13 +127,6 @@ declare const asyncTotal: <A>(thunk: () => A) => Async<unknown, unknown, A>;
99
127
  declare const async: <R, E, A>(register: (env: R, cb: (exit: Exit<E, A>) => void) => void | Canceler) => Async<R, E, A>;
100
128
  declare function asyncMap<R, E, A, B>(fa: Async<R, E, A>, f: (a: A) => B): Async<R, E, B>;
101
129
  declare function asyncFlatMap<R, E, A, B>(fa: Async<R, E, A>, f: (a: A) => Async<R, E, B>): Async<R, E, B>;
102
- declare function toPromise<R, E, A>(eff: Async<R, E, A>, env: R): Promise<A>;
103
- declare function fromPromise<R, E, A>(thunk: (env: R) => Promise<A>, onError: (e: unknown) => E): Async<R, E, A>;
104
- declare function fromCallback<A>(f: (cb: NodeCallback<A>) => void): Async<{}, Error, A>;
105
- declare function tryPromiseAbortable<A>(thunk: (signal: AbortSignal) => Promise<A>): Async<unknown, BrassError, A>;
106
- declare function tryPromiseAbortable<R, A>(thunk: (env: R, signal: AbortSignal) => Promise<A>): Async<R, BrassError, A>;
107
- declare function fromPromiseAbortable<E, A>(thunk: (signal: AbortSignal) => Promise<A>, onError: (e: unknown) => E): Async<unknown, E, A>;
108
- declare function fromPromiseAbortable<R, E, A>(thunk: (env: R, signal: AbortSignal) => Promise<A>, onError: (e: unknown) => E): Async<R, E, A>;
109
130
  declare function acquireRelease<R, E, A>(acquire: Async<R, E, A>, release: (res: A, exit: Exit<E, any>) => Async<R, any, any>, scope: Scope<R>): Async<R, E, A>;
110
131
  declare function asyncInterruptible<R, E, A>(register: (env: R, cb: (exit: Exit<E, A>) => void) => void | Canceler): Async<R, E, A>;
111
132
 
@@ -138,4 +159,4 @@ declare const catchAll: <R, E, A, R2, E2, B>(fa: ZIO<R, E, A>, handler: (e: E) =
138
159
  declare function orElseOptional<R, E, A, R2, A2>(fa: ZIO<R, Option<E>, A>, that: () => ZIO<R2, Option<E>, A2>): ZIO<R & R2, Option<E>, A | A2>;
139
160
  declare const end: <E>() => ZIO<unknown, Option<E>, never>;
140
161
 
141
- export { type Async as A, acquireRelease as B, asyncInterruptible as C, none as D, type Exit as E, some as F, type ScopeId as G, Scope as H, withScope as I, type Canceler as J, type CancelToken as K, makeCancelToken as L, linkAbortController as M, type None as N, type Option as O, type Some as S, type ZIO as Z, sync as a, flatMap as b, mapError as c, catchAll as d, end as e, fail as f, asyncFold as g, asyncCatchAll as h, asyncMapError as i, from as j, asyncSucceed as k, asyncFail as l, map as m, asyncSync as n, orElseOptional as o, asyncTotal as p, async as q, asyncMap as r, succeed as s, asyncFlatMap as t, unit as u, toPromise as v, fromPromise as w, fromCallback as x, tryPromiseAbortable as y, fromPromiseAbortable as z };
162
+ export { type Async as A, makeCancelToken as B, type Canceler as C, linkAbortController as D, type Exit as E, type Fiber as F, type FiberId as G, type FiberStatus as H, type Interrupted as I, type ScopeId as J, Scope as K, withScope as L, globalScheduler as M, type None as N, type Option as O, RuntimeFiber as R, Scheduler as S, type Task as T, type ZIO as Z, sync as a, flatMap as b, mapError as c, catchAll as d, end as e, fail as f, asyncFold as g, asyncCatchAll as h, asyncMapError as i, asyncSucceed as j, asyncFail as k, asyncSync as l, map as m, asyncTotal as n, orElseOptional as o, async as p, asyncMap as q, asyncFlatMap as r, succeed as s, acquireRelease as t, unit as u, asyncInterruptible as v, type Some as w, none as x, some as y, type CancelToken as z };
@@ -19,11 +19,23 @@ declare function makeCancelToken(): CancelToken & {
19
19
  */
20
20
  declare function linkAbortController(token: CancelToken, ac: AbortController): Canceler;
21
21
 
22
+ type Task = () => void;
23
+ declare class Scheduler {
24
+ private queue;
25
+ private flushing;
26
+ private requested;
27
+ schedule(task: Task, tag?: string): void;
28
+ private requestFlush;
29
+ private flush;
30
+ }
31
+ declare const globalScheduler: Scheduler;
32
+
22
33
  type FiberId = number;
23
- type FiberStatus = "Running" | "Done" | "Interrupted";
24
34
  type Interrupted = {
25
35
  readonly _tag: "Interrupted";
26
36
  };
37
+ type FiberStatus = "Running" | "Done" | "Interrupted";
38
+ type StepDecision = "Continue" | "Suspend" | "Done";
27
39
  type Fiber<E, A> = {
28
40
  readonly id: FiberId;
29
41
  readonly status: () => FiberStatus;
@@ -31,12 +43,32 @@ type Fiber<E, A> = {
31
43
  readonly interrupt: () => void;
32
44
  readonly addFinalizer: (f: (exit: Exit<E | Interrupted, A>) => void) => void;
33
45
  };
34
- type BrassError = {
35
- _tag: "Abort";
36
- } | {
37
- _tag: "PromiseRejected";
38
- reason: unknown;
39
- };
46
+ declare class RuntimeFiber<R, E, A> implements Fiber<E, A> {
47
+ private readonly scheduler;
48
+ readonly id: FiberId;
49
+ private closing;
50
+ private finishing;
51
+ private runState;
52
+ private interrupted;
53
+ private result;
54
+ private readonly joiners;
55
+ private current;
56
+ private readonly env;
57
+ private readonly stack;
58
+ private readonly fiberFinalizers;
59
+ private finalizersDrained;
60
+ constructor(effect: Async<R, E, A>, env: R, scheduler: Scheduler);
61
+ addFinalizer(f: (exit: Exit<E | Interrupted, A>) => void): void;
62
+ status(): FiberStatus;
63
+ join(cb: (exit: Exit<E | Interrupted, A>) => void): void;
64
+ interrupt(): void;
65
+ schedule(tag?: string): void;
66
+ private runFinalizersOnce;
67
+ private notify;
68
+ private onSuccess;
69
+ private onFailure;
70
+ step(): StepDecision;
71
+ }
40
72
 
41
73
  type ScopeId = number;
42
74
  declare class Scope<R> {
@@ -53,7 +85,6 @@ declare class Scope<R> {
53
85
  subScope(): Scope<R>;
54
86
  /** fork en este scope */
55
87
  fork<E, A>(eff: Async<R, E, A>, env: R): Fiber<E | Interrupted, A>;
56
- /** Cierre estructurado */
57
88
  close(exit?: Exit<any, any>): void;
58
89
  isClosed(): boolean;
59
90
  }
@@ -63,7 +94,6 @@ declare class Scope<R> {
63
94
  */
64
95
  declare function withScope<R, A>(body: (scope: Scope<R>) => A): A;
65
96
 
66
- type NodeCallback<A> = (err: Error | null, result: A) => void;
67
97
  type Async<R, E, A> = {
68
98
  _tag: "Succeed";
69
99
  value: A;
@@ -89,8 +119,6 @@ type Async<R, E, A> = {
89
119
  declare function asyncFold<R, E, A, B>(fa: Async<R, E, A>, onFailure: (e: E) => Async<R, E, B>, onSuccess: (a: A) => Async<R, E, B>): Async<R, E, B>;
90
120
  declare function asyncCatchAll<R, E, A, R2, E2, B>(fa: Async<R, E, A>, handler: (e: E) => Async<R2, E2, B>): Async<R & R2, E2, A | B>;
91
121
  declare function asyncMapError<R, E, E2, A>(fa: Async<R, E, A>, f: (e: E) => E2): Async<R, E2, A>;
92
- declare function from<A>(f: (cb: NodeCallback<A>) => void): Async<{}, Error, A>;
93
- declare function from<A>(thunk: () => Promise<A>): Async<{}, Error, A>;
94
122
  declare function unit(): Async<unknown, unknown, undefined>;
95
123
  declare const asyncSucceed: <A>(value: A) => Async<unknown, never, A>;
96
124
  declare const asyncFail: <E>(error: E) => Async<unknown, E, never>;
@@ -99,13 +127,6 @@ declare const asyncTotal: <A>(thunk: () => A) => Async<unknown, unknown, A>;
99
127
  declare const async: <R, E, A>(register: (env: R, cb: (exit: Exit<E, A>) => void) => void | Canceler) => Async<R, E, A>;
100
128
  declare function asyncMap<R, E, A, B>(fa: Async<R, E, A>, f: (a: A) => B): Async<R, E, B>;
101
129
  declare function asyncFlatMap<R, E, A, B>(fa: Async<R, E, A>, f: (a: A) => Async<R, E, B>): Async<R, E, B>;
102
- declare function toPromise<R, E, A>(eff: Async<R, E, A>, env: R): Promise<A>;
103
- declare function fromPromise<R, E, A>(thunk: (env: R) => Promise<A>, onError: (e: unknown) => E): Async<R, E, A>;
104
- declare function fromCallback<A>(f: (cb: NodeCallback<A>) => void): Async<{}, Error, A>;
105
- declare function tryPromiseAbortable<A>(thunk: (signal: AbortSignal) => Promise<A>): Async<unknown, BrassError, A>;
106
- declare function tryPromiseAbortable<R, A>(thunk: (env: R, signal: AbortSignal) => Promise<A>): Async<R, BrassError, A>;
107
- declare function fromPromiseAbortable<E, A>(thunk: (signal: AbortSignal) => Promise<A>, onError: (e: unknown) => E): Async<unknown, E, A>;
108
- declare function fromPromiseAbortable<R, E, A>(thunk: (env: R, signal: AbortSignal) => Promise<A>, onError: (e: unknown) => E): Async<R, E, A>;
109
130
  declare function acquireRelease<R, E, A>(acquire: Async<R, E, A>, release: (res: A, exit: Exit<E, any>) => Async<R, any, any>, scope: Scope<R>): Async<R, E, A>;
110
131
  declare function asyncInterruptible<R, E, A>(register: (env: R, cb: (exit: Exit<E, A>) => void) => void | Canceler): Async<R, E, A>;
111
132
 
@@ -138,4 +159,4 @@ declare const catchAll: <R, E, A, R2, E2, B>(fa: ZIO<R, E, A>, handler: (e: E) =
138
159
  declare function orElseOptional<R, E, A, R2, A2>(fa: ZIO<R, Option<E>, A>, that: () => ZIO<R2, Option<E>, A2>): ZIO<R & R2, Option<E>, A | A2>;
139
160
  declare const end: <E>() => ZIO<unknown, Option<E>, never>;
140
161
 
141
- export { type Async as A, acquireRelease as B, asyncInterruptible as C, none as D, type Exit as E, some as F, type ScopeId as G, Scope as H, withScope as I, type Canceler as J, type CancelToken as K, makeCancelToken as L, linkAbortController as M, type None as N, type Option as O, type Some as S, type ZIO as Z, sync as a, flatMap as b, mapError as c, catchAll as d, end as e, fail as f, asyncFold as g, asyncCatchAll as h, asyncMapError as i, from as j, asyncSucceed as k, asyncFail as l, map as m, asyncSync as n, orElseOptional as o, asyncTotal as p, async as q, asyncMap as r, succeed as s, asyncFlatMap as t, unit as u, toPromise as v, fromPromise as w, fromCallback as x, tryPromiseAbortable as y, fromPromiseAbortable as z };
162
+ export { type Async as A, makeCancelToken as B, type Canceler as C, linkAbortController as D, type Exit as E, type Fiber as F, type FiberId as G, type FiberStatus as H, type Interrupted as I, type ScopeId as J, Scope as K, withScope as L, globalScheduler as M, type None as N, type Option as O, RuntimeFiber as R, Scheduler as S, type Task as T, type ZIO as Z, sync as a, flatMap as b, mapError as c, catchAll as d, end as e, fail as f, asyncFold as g, asyncCatchAll as h, asyncMapError as i, asyncSucceed as j, asyncFail as k, asyncSync as l, map as m, asyncTotal as n, orElseOptional as o, async as p, asyncMap as q, asyncFlatMap as r, succeed as s, acquireRelease as t, unit as u, asyncInterruptible as v, type Some as w, none as x, some as y, type CancelToken as z };
@@ -1,4 +1,4 @@
1
- import { A as Async } from '../effect-D4h--Rys.mjs';
1
+ import { A as Async } from '../effect-Dt7h2Ttr.mjs';
2
2
 
3
3
  type HttpError = {
4
4
  _tag: "Abort";
@@ -1,4 +1,4 @@
1
- import { A as Async } from '../effect-D4h--Rys.js';
1
+ import { A as Async } from '../effect-Dt7h2Ttr.js';
2
2
 
3
3
  type HttpError = {
4
4
  _tag: "Abort";
@@ -1 +1 @@
1
- 'use strict';var chunk77P3VCG2_js=require('../chunk-77P3VCG2.js');var h=s=>s instanceof DOMException&&s.name==="AbortError"?{_tag:"Abort"}:typeof s=="object"&&s&&"_tag"in s?s:{_tag:"FetchError",message:String(s)};function b(s={}){let p=s.baseUrl??"",d=s.headers??{},n=t=>chunk77P3VCG2_js.t(async e=>{let r;try{r=new URL(t.url,p);}catch{throw {_tag:"BadUrl",message:`URL inv\xE1lida: ${t.url}`}}let g=performance.now(),o=await fetch(r,{...t,headers:{...d,...t.headers??{}},signal:e}),c=await o.text(),i={};return o.headers.forEach((u,m)=>i[m]=u),{status:o.status,statusText:o.statusText,headers:i,bodyText:c,ms:Math.round(performance.now()-g)}},h);return {get:(t,e)=>n({url:t,method:"GET",...e??{}}),post:(t,e,r)=>n({url:t,method:"POST",body:e&&e.length>0?e:void 0,...r??{}}),getText:(t,e)=>n({url:t,method:"GET",...e??{}}).map(r=>r.bodyText),getJson:(t,e)=>n({url:t,method:"GET",...e??{}}).map(r=>JSON.parse(r.bodyText)),postJson:(t,e,r)=>n({url:t,method:"POST",headers:{"content-type":"application/json",...r?.headers??{}},body:JSON.stringify(e),...r??{}})}}exports.makeHttp=b;
1
+ 'use strict';var chunkREJAVP4D_js=require('../chunk-REJAVP4D.js');var h=s=>s instanceof DOMException&&s.name==="AbortError"?{_tag:"Abort"}:typeof s=="object"&&s&&"_tag"in s?s:{_tag:"FetchError",message:String(s)};function y(s={}){let p=s.baseUrl??"",d=s.headers??{},n=t=>chunkREJAVP4D_js.x(async e=>{let r;try{r=new URL(t.url,p);}catch{throw {_tag:"BadUrl",message:`URL inv\xE1lida: ${t.url}`}}let g=performance.now(),o=await fetch(r,{...t,headers:{...d,...t.headers??{}},signal:e}),c=await o.text(),i={};return o.headers.forEach((m,u)=>i[u]=m),{status:o.status,statusText:o.statusText,headers:i,bodyText:c,ms:Math.round(performance.now()-g)}},h);return {get:(t,e)=>n({url:t,method:"GET",...e??{}}),post:(t,e,r)=>n({url:t,method:"POST",body:e&&e.length>0?e:void 0,...r??{}}),getText:(t,e)=>n({url:t,method:"GET",...e??{}}).map(r=>r.bodyText),getJson:(t,e)=>n({url:t,method:"GET",...e??{}}).map(r=>JSON.parse(r.bodyText)),postJson:(t,e,r)=>n({url:t,method:"POST",headers:{"content-type":"application/json",...r?.headers??{}},body:JSON.stringify(e),...r??{}})}}exports.makeHttp=y;
@@ -1 +1 @@
1
- import {t}from'../chunk-EZTDSZ4Y.mjs';var h=s=>s instanceof DOMException&&s.name==="AbortError"?{_tag:"Abort"}:typeof s=="object"&&s&&"_tag"in s?s:{_tag:"FetchError",message:String(s)};function b(s={}){let p=s.baseUrl??"",d=s.headers??{},n=t$1=>t(async e=>{let r;try{r=new URL(t$1.url,p);}catch{throw {_tag:"BadUrl",message:`URL inv\xE1lida: ${t$1.url}`}}let g=performance.now(),o=await fetch(r,{...t$1,headers:{...d,...t$1.headers??{}},signal:e}),c=await o.text(),i={};return o.headers.forEach((u,m)=>i[m]=u),{status:o.status,statusText:o.statusText,headers:i,bodyText:c,ms:Math.round(performance.now()-g)}},h);return {get:(t,e)=>n({url:t,method:"GET",...e??{}}),post:(t,e,r)=>n({url:t,method:"POST",body:e&&e.length>0?e:void 0,...r??{}}),getText:(t,e)=>n({url:t,method:"GET",...e??{}}).map(r=>r.bodyText),getJson:(t,e)=>n({url:t,method:"GET",...e??{}}).map(r=>JSON.parse(r.bodyText)),postJson:(t,e,r)=>n({url:t,method:"POST",headers:{"content-type":"application/json",...r?.headers??{}},body:JSON.stringify(e),...r??{}})}}export{b as makeHttp};
1
+ import {x}from'../chunk-JLFYFKQ2.mjs';var h=s=>s instanceof DOMException&&s.name==="AbortError"?{_tag:"Abort"}:typeof s=="object"&&s&&"_tag"in s?s:{_tag:"FetchError",message:String(s)};function y(s={}){let p=s.baseUrl??"",d=s.headers??{},n=t=>x(async e=>{let r;try{r=new URL(t.url,p);}catch{throw {_tag:"BadUrl",message:`URL inv\xE1lida: ${t.url}`}}let g=performance.now(),o=await fetch(r,{...t,headers:{...d,...t.headers??{}},signal:e}),c=await o.text(),i={};return o.headers.forEach((m,u)=>i[u]=m),{status:o.status,statusText:o.statusText,headers:i,bodyText:c,ms:Math.round(performance.now()-g)}},h);return {get:(t,e)=>n({url:t,method:"GET",...e??{}}),post:(t,e,r)=>n({url:t,method:"POST",body:e&&e.length>0?e:void 0,...r??{}}),getText:(t,e)=>n({url:t,method:"GET",...e??{}}).map(r=>r.bodyText),getJson:(t,e)=>n({url:t,method:"GET",...e??{}}).map(r=>JSON.parse(r.bodyText)),postJson:(t,e,r)=>n({url:t,method:"POST",headers:{"content-type":"application/json",...r?.headers??{}},body:JSON.stringify(e),...r??{}})}}export{y as makeHttp};
package/dist/index.d.mts CHANGED
@@ -1,16 +1,5 @@
1
- import { Z as ZIO, O as Option, A as Async } from './effect-D4h--Rys.mjs';
2
- export { K as CancelToken, J as Canceler, E as Exit, N as None, H as Scope, G as ScopeId, S as Some, B as acquireRelease, q as async, h as asyncCatchAll, l as asyncFail, t as asyncFlatMap, g as asyncFold, C as asyncInterruptible, r as asyncMap, i as asyncMapError, k as asyncSucceed, n as asyncSync, p as asyncTotal, d as catchAll, e as end, f as fail, b as flatMap, j as from, x as fromCallback, w as fromPromise, z as fromPromiseAbortable, M as linkAbortController, L as makeCancelToken, m as map, c as mapError, D as none, o as orElseOptional, F as some, s as succeed, a as sync, v as toPromise, y as tryPromiseAbortable, u as unit, I as withScope } from './effect-D4h--Rys.mjs';
3
-
4
- type Task = () => void;
5
- declare class Scheduler {
6
- private queue;
7
- private flushing;
8
- private requested;
9
- schedule(task: Task, tag?: string): void;
10
- private requestFlush;
11
- private flush;
12
- }
13
- declare const globalScheduler: Scheduler;
1
+ import { Z as ZIO, O as Option, A as Async, S as Scheduler, F as Fiber, E as Exit, I as Interrupted } from './effect-Dt7h2Ttr.mjs';
2
+ export { z as CancelToken, C as Canceler, G as FiberId, H as FiberStatus, N as None, R as RuntimeFiber, K as Scope, J as ScopeId, w as Some, T as Task, t as acquireRelease, p as async, h as asyncCatchAll, k as asyncFail, r as asyncFlatMap, g as asyncFold, v as asyncInterruptible, q as asyncMap, i as asyncMapError, j as asyncSucceed, l as asyncSync, n as asyncTotal, d as catchAll, e as end, f as fail, b as flatMap, M as globalScheduler, D as linkAbortController, B as makeCancelToken, m as map, c as mapError, x as none, o as orElseOptional, y as some, s as succeed, a as sync, u as unit, L as withScope } from './effect-Dt7h2Ttr.mjs';
14
3
 
15
4
  type Empty<R, E, A> = {
16
5
  readonly _tag: "Empty";
@@ -32,12 +21,20 @@ type FromPull<R, E, A> = {
32
21
  readonly _tag: "FromPull";
33
22
  readonly pull: ZIO<R, Option<E>, [A, ZStream<R, E, A>]>;
34
23
  };
35
- type ZStream<R, E, A> = Empty<R, E, A> | Emit<R, E, A> | Concat<R, E, A> | FromPull<R, E, A> | Flatten<R, E, A>;
24
+ type Merge<R, E, A> = {
25
+ readonly _tag: "Merge";
26
+ readonly left: ZStream<R, E, A>;
27
+ readonly right: ZStream<R, E, A>;
28
+ readonly flip: boolean;
29
+ };
30
+ type ZStream<R, E, A> = Empty<R, E, A> | Emit<R, E, A> | Concat<R, E, A> | FromPull<R, E, A> | Flatten<R, E, A> | Merge<R, E, A>;
36
31
  declare const fromPull: <R, E, A>(pull: ZIO<R, Option<E>, [A, ZStream<R, E, A>]>) => ZStream<R, E, A>;
32
+ declare const mergeStream: <R, E, A>(left: ZStream<R, E, A>, right: ZStream<R, E, A>, flip?: boolean) => ZStream<R, E, A>;
37
33
  declare const emptyStream: <R, E, A>() => ZStream<R, E, A>;
38
34
  declare const emitStream: <R, E, A>(value: ZIO<R, E, A>) => ZStream<R, E, A>;
39
35
  declare const concatStream: <R, E, A>(left: ZStream<R, E, A>, right: ZStream<R, E, A>) => ZStream<R, E, A>;
40
36
  declare const flattenStream: <R, E, A>(stream: ZStream<R, E, ZStream<R, E, A>>) => ZStream<R, E, A>;
37
+ declare function merge<R, E, A>(left: ZStream<R, E, A>, right: ZStream<R, E, A>): ZStream<R, E, A>;
41
38
  declare function uncons<R, E, A>(self: ZStream<R, E, A>): ZIO<R, Option<E>, [A, ZStream<R, E, A>]>;
42
39
  declare function mapStream<R, E, A, B>(self: ZStream<R, E, A>, f: (a: A) => B): ZStream<R, E, B>;
43
40
  declare function rangeStream(start: number, end: number): ZStream<unknown, never, number>;
@@ -46,4 +43,23 @@ declare function foreachStream<R, E, A, R2, E2>(stream: ZStream<R, E, A>, f: (a:
46
43
  declare function fromArray<A>(values: readonly A[]): ZStream<unknown, never, A>;
47
44
  declare function collectStream<R, E, A>(stream: ZStream<R, E, A>): ZIO<R, E, A[]>;
48
45
 
49
- export { Async, type Concat, type Emit, type Empty, type Flatten, type FromPull, Option, Scheduler, type Task, ZIO, type ZStream, collectStream, concatStream, emitStream, emptyStream, flattenStream, foreachStream, fromArray, fromPull, globalScheduler, mapStream, rangeStream, uncons, zip };
46
+ type NodeCallback<A> = (err: Error | null, result: A) => void;
47
+ declare function from<A>(f: (cb: NodeCallback<A>) => void): Async<{}, Error, A>;
48
+ declare function from<A>(thunk: () => Promise<A>): Async<{}, Error, A>;
49
+ type BrassError = {
50
+ _tag: "Abort";
51
+ } | {
52
+ _tag: "PromiseRejected";
53
+ reason: unknown;
54
+ };
55
+ declare function fork<R, E, A>(effect: Async<R, E, A>, env: R, scheduler?: Scheduler): Fiber<E, A>;
56
+ declare function unsafeRunAsync<R, E, A>(effect: Async<R, E, A>, env: R, cb: (exit: Exit<E | Interrupted, A>) => void): void;
57
+ declare function toPromise<R, E, A>(eff: Async<R, E, A>, env: R): Promise<A>;
58
+ declare function fromPromise<R, E, A>(thunk: (env: R) => Promise<A>, onError: (e: unknown) => E): Async<R, E, A>;
59
+ declare function fromCallback<A>(f: (cb: NodeCallback<A>) => void): Async<{}, Error, A>;
60
+ declare function tryPromiseAbortable<A>(thunk: (signal: AbortSignal) => Promise<A>): Async<unknown, BrassError, A>;
61
+ declare function tryPromiseAbortable<R, A>(thunk: (env: R, signal: AbortSignal) => Promise<A>): Async<R, BrassError, A>;
62
+ declare function fromPromiseAbortable<E, A>(thunk: (signal: AbortSignal) => Promise<A>, onError: (e: unknown) => E): Async<unknown, E, A>;
63
+ declare function fromPromiseAbortable<R, E, A>(thunk: (env: R, signal: AbortSignal) => Promise<A>, onError: (e: unknown) => E): Async<R, E, A>;
64
+
65
+ export { Async, type BrassError, type Concat, type Emit, type Empty, Exit, Fiber, type Flatten, type FromPull, Interrupted, type Merge, Option, Scheduler, ZIO, type ZStream, collectStream, concatStream, emitStream, emptyStream, flattenStream, foreachStream, fork, from, fromArray, fromCallback, fromPromise, fromPromiseAbortable, fromPull, mapStream, merge, mergeStream, rangeStream, toPromise, tryPromiseAbortable, uncons, unsafeRunAsync, zip };
package/dist/index.d.ts CHANGED
@@ -1,16 +1,5 @@
1
- import { Z as ZIO, O as Option, A as Async } from './effect-D4h--Rys.js';
2
- export { K as CancelToken, J as Canceler, E as Exit, N as None, H as Scope, G as ScopeId, S as Some, B as acquireRelease, q as async, h as asyncCatchAll, l as asyncFail, t as asyncFlatMap, g as asyncFold, C as asyncInterruptible, r as asyncMap, i as asyncMapError, k as asyncSucceed, n as asyncSync, p as asyncTotal, d as catchAll, e as end, f as fail, b as flatMap, j as from, x as fromCallback, w as fromPromise, z as fromPromiseAbortable, M as linkAbortController, L as makeCancelToken, m as map, c as mapError, D as none, o as orElseOptional, F as some, s as succeed, a as sync, v as toPromise, y as tryPromiseAbortable, u as unit, I as withScope } from './effect-D4h--Rys.js';
3
-
4
- type Task = () => void;
5
- declare class Scheduler {
6
- private queue;
7
- private flushing;
8
- private requested;
9
- schedule(task: Task, tag?: string): void;
10
- private requestFlush;
11
- private flush;
12
- }
13
- declare const globalScheduler: Scheduler;
1
+ import { Z as ZIO, O as Option, A as Async, S as Scheduler, F as Fiber, E as Exit, I as Interrupted } from './effect-Dt7h2Ttr.js';
2
+ export { z as CancelToken, C as Canceler, G as FiberId, H as FiberStatus, N as None, R as RuntimeFiber, K as Scope, J as ScopeId, w as Some, T as Task, t as acquireRelease, p as async, h as asyncCatchAll, k as asyncFail, r as asyncFlatMap, g as asyncFold, v as asyncInterruptible, q as asyncMap, i as asyncMapError, j as asyncSucceed, l as asyncSync, n as asyncTotal, d as catchAll, e as end, f as fail, b as flatMap, M as globalScheduler, D as linkAbortController, B as makeCancelToken, m as map, c as mapError, x as none, o as orElseOptional, y as some, s as succeed, a as sync, u as unit, L as withScope } from './effect-Dt7h2Ttr.js';
14
3
 
15
4
  type Empty<R, E, A> = {
16
5
  readonly _tag: "Empty";
@@ -32,12 +21,20 @@ type FromPull<R, E, A> = {
32
21
  readonly _tag: "FromPull";
33
22
  readonly pull: ZIO<R, Option<E>, [A, ZStream<R, E, A>]>;
34
23
  };
35
- type ZStream<R, E, A> = Empty<R, E, A> | Emit<R, E, A> | Concat<R, E, A> | FromPull<R, E, A> | Flatten<R, E, A>;
24
+ type Merge<R, E, A> = {
25
+ readonly _tag: "Merge";
26
+ readonly left: ZStream<R, E, A>;
27
+ readonly right: ZStream<R, E, A>;
28
+ readonly flip: boolean;
29
+ };
30
+ type ZStream<R, E, A> = Empty<R, E, A> | Emit<R, E, A> | Concat<R, E, A> | FromPull<R, E, A> | Flatten<R, E, A> | Merge<R, E, A>;
36
31
  declare const fromPull: <R, E, A>(pull: ZIO<R, Option<E>, [A, ZStream<R, E, A>]>) => ZStream<R, E, A>;
32
+ declare const mergeStream: <R, E, A>(left: ZStream<R, E, A>, right: ZStream<R, E, A>, flip?: boolean) => ZStream<R, E, A>;
37
33
  declare const emptyStream: <R, E, A>() => ZStream<R, E, A>;
38
34
  declare const emitStream: <R, E, A>(value: ZIO<R, E, A>) => ZStream<R, E, A>;
39
35
  declare const concatStream: <R, E, A>(left: ZStream<R, E, A>, right: ZStream<R, E, A>) => ZStream<R, E, A>;
40
36
  declare const flattenStream: <R, E, A>(stream: ZStream<R, E, ZStream<R, E, A>>) => ZStream<R, E, A>;
37
+ declare function merge<R, E, A>(left: ZStream<R, E, A>, right: ZStream<R, E, A>): ZStream<R, E, A>;
41
38
  declare function uncons<R, E, A>(self: ZStream<R, E, A>): ZIO<R, Option<E>, [A, ZStream<R, E, A>]>;
42
39
  declare function mapStream<R, E, A, B>(self: ZStream<R, E, A>, f: (a: A) => B): ZStream<R, E, B>;
43
40
  declare function rangeStream(start: number, end: number): ZStream<unknown, never, number>;
@@ -46,4 +43,23 @@ declare function foreachStream<R, E, A, R2, E2>(stream: ZStream<R, E, A>, f: (a:
46
43
  declare function fromArray<A>(values: readonly A[]): ZStream<unknown, never, A>;
47
44
  declare function collectStream<R, E, A>(stream: ZStream<R, E, A>): ZIO<R, E, A[]>;
48
45
 
49
- export { Async, type Concat, type Emit, type Empty, type Flatten, type FromPull, Option, Scheduler, type Task, ZIO, type ZStream, collectStream, concatStream, emitStream, emptyStream, flattenStream, foreachStream, fromArray, fromPull, globalScheduler, mapStream, rangeStream, uncons, zip };
46
+ type NodeCallback<A> = (err: Error | null, result: A) => void;
47
+ declare function from<A>(f: (cb: NodeCallback<A>) => void): Async<{}, Error, A>;
48
+ declare function from<A>(thunk: () => Promise<A>): Async<{}, Error, A>;
49
+ type BrassError = {
50
+ _tag: "Abort";
51
+ } | {
52
+ _tag: "PromiseRejected";
53
+ reason: unknown;
54
+ };
55
+ declare function fork<R, E, A>(effect: Async<R, E, A>, env: R, scheduler?: Scheduler): Fiber<E, A>;
56
+ declare function unsafeRunAsync<R, E, A>(effect: Async<R, E, A>, env: R, cb: (exit: Exit<E | Interrupted, A>) => void): void;
57
+ declare function toPromise<R, E, A>(eff: Async<R, E, A>, env: R): Promise<A>;
58
+ declare function fromPromise<R, E, A>(thunk: (env: R) => Promise<A>, onError: (e: unknown) => E): Async<R, E, A>;
59
+ declare function fromCallback<A>(f: (cb: NodeCallback<A>) => void): Async<{}, Error, A>;
60
+ declare function tryPromiseAbortable<A>(thunk: (signal: AbortSignal) => Promise<A>): Async<unknown, BrassError, A>;
61
+ declare function tryPromiseAbortable<R, A>(thunk: (env: R, signal: AbortSignal) => Promise<A>): Async<R, BrassError, A>;
62
+ declare function fromPromiseAbortable<E, A>(thunk: (signal: AbortSignal) => Promise<A>, onError: (e: unknown) => E): Async<unknown, E, A>;
63
+ declare function fromPromiseAbortable<R, E, A>(thunk: (env: R, signal: AbortSignal) => Promise<A>, onError: (e: unknown) => E): Async<R, E, A>;
64
+
65
+ export { Async, type BrassError, type Concat, type Emit, type Empty, Exit, Fiber, type Flatten, type FromPull, Interrupted, type Merge, Option, Scheduler, ZIO, type ZStream, collectStream, concatStream, emitStream, emptyStream, flattenStream, foreachStream, fork, from, fromArray, fromCallback, fromPromise, fromPromiseAbortable, fromPull, mapStream, merge, mergeStream, rangeStream, toPromise, tryPromiseAbortable, uncons, unsafeRunAsync, zip };
package/dist/index.js CHANGED
@@ -1 +1 @@
1
- 'use strict';var chunk77P3VCG2_js=require('./chunk-77P3VCG2.js');var l={_tag:"None"},y=e=>({_tag:"Some",value:e});var Z=e=>chunk77P3VCG2_js.i(e),u=e=>chunk77P3VCG2_js.j(e),X=e=>chunk77P3VCG2_js.k(t=>e(t)),A=(e,t)=>chunk77P3VCG2_js.n(e,t),_=(e,t)=>chunk77P3VCG2_js.o(e,n=>t(n)),O=(e,t)=>chunk77P3VCG2_js.f(e,t),Y=(e,t)=>chunk77P3VCG2_js.d(e,n=>t(n),n=>chunk77P3VCG2_js.i(n));function x(e,t){return chunk77P3VCG2_js.d(e,n=>n._tag==="Some"?chunk77P3VCG2_js.j(n):t(),n=>chunk77P3VCG2_js.i(n))}var $=()=>u(l);var h=e=>e._tag==="None"?l:y(e.value),g=e=>({_tag:"FromPull",pull:e}),w=()=>({_tag:"Empty"}),F=e=>({_tag:"Emit",value:e}),d=(e,t)=>({_tag:"Concat",left:e,right:t}),v=e=>({_tag:"Flatten",stream:e});function i(e){switch(e._tag){case "Empty":return u(l);case "Emit":return A(O(e.value,t=>y(t)),t=>[t,w()]);case "FromPull":return e.pull;case "Concat":return x(A(i(e.left),([t,n])=>[t,d(n,e.right)]),()=>i(e.right));case "Flatten":return _(i(e.stream),([t,n])=>x(A(i(t),([r,o])=>[r,d(o,v(n))]),()=>i(v(n))))}}function m(e,t){switch(e._tag){case "Empty":return w();case "Emit":return F(A(e.value,t));case "FromPull":return g(A(e.pull,([n,r])=>[t(n),m(r,t)]));case "Concat":return d(m(e.left,t),m(e.right,t));case "Flatten":{let n=m(e.stream,r=>m(r,t));return v(n)}}}function se(e,t){let n=r=>g(r>t?chunk77P3VCG2_js.j(l):chunk77P3VCG2_js.i([r,n(r+1)]));return n(e)}function b(e,t){let n=chunk77P3VCG2_js.d(chunk77P3VCG2_js.f(i(e),r=>h(r)),r=>chunk77P3VCG2_js.j(r),([r,o])=>chunk77P3VCG2_js.d(chunk77P3VCG2_js.f(i(t),E=>h(E)),E=>chunk77P3VCG2_js.j(E),([E,S])=>chunk77P3VCG2_js.i([[r,E],b(o,S)])));return g(n)}function ie(e,t){let n=r=>chunk77P3VCG2_js.d(chunk77P3VCG2_js.f(i(r),o=>h(o)),o=>o._tag==="None"?chunk77P3VCG2_js.i(void 0):chunk77P3VCG2_js.j(o),([o,E])=>chunk77P3VCG2_js.o(chunk77P3VCG2_js.f(t(o),S=>y(S)),()=>n(E)));return chunk77P3VCG2_js.d(n(e),r=>r._tag==="None"?chunk77P3VCG2_js.i(void 0):chunk77P3VCG2_js.j(r.value),()=>chunk77P3VCG2_js.i(void 0))}function pe(e){let t=w();for(let n=e.length-1;n>=0;n--){let r=F(Z(e[n]));t=d(r,t);}return t}function le(e){let t=(n,r)=>chunk77P3VCG2_js.d(i(n),o=>o._tag==="None"?Z(r):u(o),([o,E])=>t(E,[...r,o]));return O(t(e,[]),n=>{if(n._tag==="Some")return n.value;throw new Error("unreachable: stream end handled as success")})}var k=1,I=class e{constructor(t){this.env=t;this.id=k++;}id;closed=false;children=new Set;subScopes=new Set;finalizers=[];addFinalizer(t){if(this.closed)throw new Error("Trying to add finalizer to closed scope");this.finalizers.push(t);}subScope(){if(this.closed)throw new Error("Scope closed");let t=new e(this.env);return this.subScopes.add(t),t}fork(t,n){if(this.closed)throw new Error("Scope closed");let r=chunk77P3VCG2_js.c(t,n);return this.children.add(r),r.join(()=>{this.children.delete(r);}),r}close(t={_tag:"Success",value:void 0}){if(!this.closed){this.closed=true;for(let n of this.children)n.interrupt();for(let n of this.subScopes)n.close(t);for(;this.finalizers.length>0;){let r=this.finalizers.pop()(t);chunk77P3VCG2_js.c(r,this.env);}this.children.clear(),this.subScopes.clear();}}isClosed(){return this.closed}};function ue(e){let t=new I({});try{return e(t)}finally{t.close();}}function Se(){let e=false,t=new Set;return {isCancelled:()=>e,onCancel:r=>{if(e){try{r();}catch{}return ()=>{}}return t.add(r),()=>{t.delete(r);}},cancel:()=>{if(!e){e=true;for(let r of t)try{r();}catch{}t.clear();}}}}function fe(e,t){return e.onCancel(()=>t.abort())}Object.defineProperty(exports,"Scheduler",{enumerable:true,get:function(){return chunk77P3VCG2_js.a}});Object.defineProperty(exports,"acquireRelease",{enumerable:true,get:function(){return chunk77P3VCG2_js.u}});Object.defineProperty(exports,"async",{enumerable:true,get:function(){return chunk77P3VCG2_js.m}});Object.defineProperty(exports,"asyncCatchAll",{enumerable:true,get:function(){return chunk77P3VCG2_js.e}});Object.defineProperty(exports,"asyncFail",{enumerable:true,get:function(){return chunk77P3VCG2_js.j}});Object.defineProperty(exports,"asyncFlatMap",{enumerable:true,get:function(){return chunk77P3VCG2_js.o}});Object.defineProperty(exports,"asyncFold",{enumerable:true,get:function(){return chunk77P3VCG2_js.d}});Object.defineProperty(exports,"asyncInterruptible",{enumerable:true,get:function(){return chunk77P3VCG2_js.v}});Object.defineProperty(exports,"asyncMap",{enumerable:true,get:function(){return chunk77P3VCG2_js.n}});Object.defineProperty(exports,"asyncMapError",{enumerable:true,get:function(){return chunk77P3VCG2_js.f}});Object.defineProperty(exports,"asyncSucceed",{enumerable:true,get:function(){return chunk77P3VCG2_js.i}});Object.defineProperty(exports,"asyncSync",{enumerable:true,get:function(){return chunk77P3VCG2_js.k}});Object.defineProperty(exports,"asyncTotal",{enumerable:true,get:function(){return chunk77P3VCG2_js.l}});Object.defineProperty(exports,"from",{enumerable:true,get:function(){return chunk77P3VCG2_js.g}});Object.defineProperty(exports,"fromCallback",{enumerable:true,get:function(){return chunk77P3VCG2_js.r}});Object.defineProperty(exports,"fromPromise",{enumerable:true,get:function(){return chunk77P3VCG2_js.q}});Object.defineProperty(exports,"fromPromiseAbortable",{enumerable:true,get:function(){return chunk77P3VCG2_js.t}});Object.defineProperty(exports,"globalScheduler",{enumerable:true,get:function(){return chunk77P3VCG2_js.b}});Object.defineProperty(exports,"toPromise",{enumerable:true,get:function(){return chunk77P3VCG2_js.p}});Object.defineProperty(exports,"tryPromiseAbortable",{enumerable:true,get:function(){return chunk77P3VCG2_js.s}});Object.defineProperty(exports,"unit",{enumerable:true,get:function(){return chunk77P3VCG2_js.h}});exports.Scope=I;exports.catchAll=Y;exports.collectStream=le;exports.concatStream=d;exports.emitStream=F;exports.emptyStream=w;exports.end=$;exports.fail=u;exports.flatMap=_;exports.flattenStream=v;exports.foreachStream=ie;exports.fromArray=pe;exports.fromPull=g;exports.linkAbortController=fe;exports.makeCancelToken=Se;exports.map=A;exports.mapError=O;exports.mapStream=m;exports.none=l;exports.orElseOptional=x;exports.rangeStream=se;exports.some=y;exports.succeed=Z;exports.sync=X;exports.uncons=i;exports.withScope=ue;exports.zip=b;
1
+ 'use strict';var chunkREJAVP4D_js=require('./chunk-REJAVP4D.js');var S={_tag:"None"},b=e=>({_tag:"Some",value:e});var k=e=>chunkREJAVP4D_js.e(e),_=e=>chunkREJAVP4D_js.f(e),Ee=e=>chunkREJAVP4D_js.g(r=>e(r)),g=(e,r)=>chunkREJAVP4D_js.j(e,r),N=(e,r)=>chunkREJAVP4D_js.k(e,t=>r(t)),w=(e,r)=>chunkREJAVP4D_js.c(e,r),ie=(e,r)=>chunkREJAVP4D_js.a(e,t=>r(t),t=>chunkREJAVP4D_js.e(t));function C(e,r){return chunkREJAVP4D_js.a(e,t=>t._tag==="Some"?chunkREJAVP4D_js.f(t):r(),t=>chunkREJAVP4D_js.e(t))}var pe=()=>_(S);function Ae(){let e=false,r=new Set;return {isCancelled:()=>e,onCancel:n=>{if(e){try{n();}catch{}return ()=>{}}return r.add(n),()=>{r.delete(n);}},cancel:()=>{if(!e){e=true;for(let n of r)try{n();}catch{}r.clear();}}}}function Re(e,r){return e.onCancel(()=>r.abort())}var H=1,x=class e{constructor(r){this.env=r;this.id=H++;}id;closed=false;children=new Set;subScopes=new Set;finalizers=[];addFinalizer(r){if(this.closed)throw new Error("Trying to add finalizer to closed scope");this.finalizers.push(r);}subScope(){if(this.closed)throw new Error("Scope closed");let r=new e(this.env);return this.subScopes.add(r),r}fork(r,t){if(this.closed)throw new Error("Scope closed");let n=chunkREJAVP4D_js.r(r,t);return this.children.add(n),n.join(()=>{this.children.delete(n);}),n}close(r={_tag:"Success",value:void 0}){if(!this.closed){for(this.closed=true,this.children.forEach(t=>t.interrupt()),this.subScopes.forEach(t=>t.close(r));this.finalizers.length>0;){let n=this.finalizers.pop()(r);chunkREJAVP4D_js.r(n,this.env);}this.children.clear(),this.subScopes.clear();}}isClosed(){return this.closed}};function de(e){let r=new x({});try{return e(r)}finally{r.close();}}function T(e,r,t,n,o){return chunkREJAVP4D_js.i((a,c)=>{let E=t.subScope(),s=false,R=E.fork(e,a),d=E.fork(r,a),m=u=>{E.fork(u,a).join(f=>{E.close(f),c(f);});};R.join(u=>{s||(s=true,m(n(u,d,E)));}),d.join(u=>{s||(s=true,m(o(u,R,E)));});})}var P=e=>e._tag==="None"?S:b(e.value),Z=e=>({_tag:"FromPull",pull:e}),we=(e,r,t=true)=>({_tag:"Merge",left:e,right:r,flip:t}),$=()=>({_tag:"Empty"}),W=e=>({_tag:"Emit",value:e}),F=(e,r)=>({_tag:"Concat",left:e,right:r}),M=e=>({_tag:"Flatten",stream:e});function L(e,r,t,n,o){return (a,c,E)=>{if(console.log(`[mergePull#${o}] winner=${e} exit=${a._tag}`),a._tag==="Failure"&&console.log(`[mergePull#${o}] failure error=`,a.error),a._tag==="Success"&&console.log(`[mergePull#${o}] success -> interrupt other`),a._tag==="Success"){let[d,m]=a.value;c.interrupt();let u=Z(e==="L"?v(m,t,!n,o):v(r,m,!n,o));return chunkREJAVP4D_js.e([d,u])}let s=a.error;if(typeof s=="object"&&s!==null&&s._tag==="Interrupted")return chunkREJAVP4D_js.f(s);let R=s;return R._tag==="None"?l(e==="L"?t:r):chunkREJAVP4D_js.f(R)}}function v(e,r,t,n){return chunkREJAVP4D_js.i((o,a)=>{let c=++n;console.log(`[mergePull#${c}] start flip=${t}`);let E=new x(o);console.log(`[mergePull#${c}] built pulls`);let s=l(e),R=l(r);console.log(`[mergePull#${c}] built pulls`);let d=L("L",e,r,t,c),m=L("R",e,r,t,c);console.log(`[mergePull#${c}] calling raceWith`);let u=T(s,R,E,d,m);console.log(`[mergePull#${c}] forking handler`),E.fork(u,o).join(f=>{console.log(`[mergePull#${c}] handler joined exit=${f._tag}`),E.close(f),console.log(`[mergePull#${c}] scope closed, calling cb`),a(f);});})}function Ce(e,r){return Z(v(e,r,true,0))}function l(e){switch(e._tag){case "Empty":return _(S);case "Emit":return g(w(e.value,r=>b(r)),r=>[r,$()]);case "FromPull":return console.log("[uncons] FromPull"),e.pull;case "Concat":return C(g(l(e.left),([r,t])=>[r,F(t,e.right)]),()=>l(e.right));case "Flatten":return N(l(e.stream),([r,t])=>C(g(l(r),([n,o])=>[n,F(o,M(t))]),()=>l(M(t))));case "Merge":return console.log("[makeMergePull] defined"),v(e.left,e.right,e.flip,0)}}function h(e,r){switch(e._tag){case "Empty":return $();case "Emit":return W(g(e.value,r));case "FromPull":return Z(g(e.pull,([t,n])=>[r(t),h(n,r)]));case "Concat":return F(h(e.left,r),h(e.right,r));case "Flatten":{let t=h(e.stream,n=>h(n,r));return M(t)}}}function Pe(e,r){let t=n=>Z(n>r?chunkREJAVP4D_js.f(S):chunkREJAVP4D_js.e([n,t(n+1)]));return t(e)}function D(e,r){let t=chunkREJAVP4D_js.a(chunkREJAVP4D_js.c(l(e),n=>P(n)),n=>chunkREJAVP4D_js.f(n),([n,o])=>chunkREJAVP4D_js.a(chunkREJAVP4D_js.c(l(r),a=>P(a)),a=>chunkREJAVP4D_js.f(a),([a,c])=>chunkREJAVP4D_js.e([[n,a],D(o,c)])));return Z(t)}function Me(e,r){let t=n=>chunkREJAVP4D_js.a(chunkREJAVP4D_js.c(l(n),o=>P(o)),o=>o._tag==="None"?chunkREJAVP4D_js.e(void 0):chunkREJAVP4D_js.f(o),([o,a])=>chunkREJAVP4D_js.k(chunkREJAVP4D_js.c(r(o),c=>b(c)),()=>t(a)));return chunkREJAVP4D_js.a(t(e),n=>n._tag==="None"?chunkREJAVP4D_js.e(void 0):chunkREJAVP4D_js.f(n.value),()=>chunkREJAVP4D_js.e(void 0))}function $e(e){let r=$();for(let t=e.length-1;t>=0;t--){let n=W(k(e[t]));r=F(n,r);}return r}function je(e){let r=(t,n)=>chunkREJAVP4D_js.a(l(t),o=>o._tag==="None"?k(n):_(o),([o,a])=>r(a,[...n,o]));return w(r(e,[]),t=>{if(t._tag==="Some")return t.value;throw new Error("unreachable: stream end handled as success")})}Object.defineProperty(exports,"RuntimeFiber",{enumerable:true,get:function(){return chunkREJAVP4D_js.p}});Object.defineProperty(exports,"Scheduler",{enumerable:true,get:function(){return chunkREJAVP4D_js.n}});Object.defineProperty(exports,"acquireRelease",{enumerable:true,get:function(){return chunkREJAVP4D_js.l}});Object.defineProperty(exports,"async",{enumerable:true,get:function(){return chunkREJAVP4D_js.i}});Object.defineProperty(exports,"asyncCatchAll",{enumerable:true,get:function(){return chunkREJAVP4D_js.b}});Object.defineProperty(exports,"asyncFail",{enumerable:true,get:function(){return chunkREJAVP4D_js.f}});Object.defineProperty(exports,"asyncFlatMap",{enumerable:true,get:function(){return chunkREJAVP4D_js.k}});Object.defineProperty(exports,"asyncFold",{enumerable:true,get:function(){return chunkREJAVP4D_js.a}});Object.defineProperty(exports,"asyncInterruptible",{enumerable:true,get:function(){return chunkREJAVP4D_js.m}});Object.defineProperty(exports,"asyncMap",{enumerable:true,get:function(){return chunkREJAVP4D_js.j}});Object.defineProperty(exports,"asyncMapError",{enumerable:true,get:function(){return chunkREJAVP4D_js.c}});Object.defineProperty(exports,"asyncSucceed",{enumerable:true,get:function(){return chunkREJAVP4D_js.e}});Object.defineProperty(exports,"asyncSync",{enumerable:true,get:function(){return chunkREJAVP4D_js.g}});Object.defineProperty(exports,"asyncTotal",{enumerable:true,get:function(){return chunkREJAVP4D_js.h}});Object.defineProperty(exports,"fork",{enumerable:true,get:function(){return chunkREJAVP4D_js.r}});Object.defineProperty(exports,"from",{enumerable:true,get:function(){return chunkREJAVP4D_js.q}});Object.defineProperty(exports,"fromCallback",{enumerable:true,get:function(){return chunkREJAVP4D_js.v}});Object.defineProperty(exports,"fromPromise",{enumerable:true,get:function(){return chunkREJAVP4D_js.u}});Object.defineProperty(exports,"fromPromiseAbortable",{enumerable:true,get:function(){return chunkREJAVP4D_js.x}});Object.defineProperty(exports,"globalScheduler",{enumerable:true,get:function(){return chunkREJAVP4D_js.o}});Object.defineProperty(exports,"toPromise",{enumerable:true,get:function(){return chunkREJAVP4D_js.t}});Object.defineProperty(exports,"tryPromiseAbortable",{enumerable:true,get:function(){return chunkREJAVP4D_js.w}});Object.defineProperty(exports,"unit",{enumerable:true,get:function(){return chunkREJAVP4D_js.d}});Object.defineProperty(exports,"unsafeRunAsync",{enumerable:true,get:function(){return chunkREJAVP4D_js.s}});exports.Scope=x;exports.catchAll=ie;exports.collectStream=je;exports.concatStream=F;exports.emitStream=W;exports.emptyStream=$;exports.end=pe;exports.fail=_;exports.flatMap=N;exports.flattenStream=M;exports.foreachStream=Me;exports.fromArray=$e;exports.fromPull=Z;exports.linkAbortController=Re;exports.makeCancelToken=Ae;exports.map=g;exports.mapError=w;exports.mapStream=h;exports.merge=Ce;exports.mergeStream=we;exports.none=S;exports.orElseOptional=C;exports.rangeStream=Pe;exports.some=b;exports.succeed=k;exports.sync=Ee;exports.uncons=l;exports.withScope=de;exports.zip=D;
package/dist/index.mjs CHANGED
@@ -1 +1 @@
1
- import {d as d$1,j,o,n,f,i as i$1,k as k$1,c}from'./chunk-EZTDSZ4Y.mjs';export{a as Scheduler,u as acquireRelease,m as async,e as asyncCatchAll,j as asyncFail,o as asyncFlatMap,d as asyncFold,v as asyncInterruptible,n as asyncMap,f as asyncMapError,i as asyncSucceed,k as asyncSync,l as asyncTotal,g as from,r as fromCallback,q as fromPromise,t as fromPromiseAbortable,b as globalScheduler,p as toPromise,s as tryPromiseAbortable,h as unit}from'./chunk-EZTDSZ4Y.mjs';var l={_tag:"None"},y=e=>({_tag:"Some",value:e});var Z=e=>i$1(e),u=e=>j(e),X=e=>k$1(t=>e(t)),A=(e,t)=>n(e,t),_=(e,t)=>o(e,n=>t(n)),O=(e,t)=>f(e,t),Y=(e,t)=>d$1(e,n=>t(n),n=>i$1(n));function x(e,t){return d$1(e,n=>n._tag==="Some"?j(n):t(),n=>i$1(n))}var $=()=>u(l);var h=e=>e._tag==="None"?l:y(e.value),g=e=>({_tag:"FromPull",pull:e}),w=()=>({_tag:"Empty"}),F=e=>({_tag:"Emit",value:e}),d=(e,t)=>({_tag:"Concat",left:e,right:t}),v=e=>({_tag:"Flatten",stream:e});function i(e){switch(e._tag){case "Empty":return u(l);case "Emit":return A(O(e.value,t=>y(t)),t=>[t,w()]);case "FromPull":return e.pull;case "Concat":return x(A(i(e.left),([t,n])=>[t,d(n,e.right)]),()=>i(e.right));case "Flatten":return _(i(e.stream),([t,n])=>x(A(i(t),([r,o])=>[r,d(o,v(n))]),()=>i(v(n))))}}function m(e,t){switch(e._tag){case "Empty":return w();case "Emit":return F(A(e.value,t));case "FromPull":return g(A(e.pull,([n,r])=>[t(n),m(r,t)]));case "Concat":return d(m(e.left,t),m(e.right,t));case "Flatten":{let n=m(e.stream,r=>m(r,t));return v(n)}}}function se(e,t){let n=r=>g(r>t?j(l):i$1([r,n(r+1)]));return n(e)}function b(e,t){let n=d$1(f(i(e),r=>h(r)),r=>j(r),([r,o])=>d$1(f(i(t),E=>h(E)),E=>j(E),([E,S])=>i$1([[r,E],b(o,S)])));return g(n)}function ie(e,t){let n=r=>d$1(f(i(r),o=>h(o)),o=>o._tag==="None"?i$1(void 0):j(o),([o$1,E])=>o(f(t(o$1),S=>y(S)),()=>n(E)));return d$1(n(e),r=>r._tag==="None"?i$1(void 0):j(r.value),()=>i$1(void 0))}function pe(e){let t=w();for(let n=e.length-1;n>=0;n--){let r=F(Z(e[n]));t=d(r,t);}return t}function le(e){let t=(n,r)=>d$1(i(n),o=>o._tag==="None"?Z(r):u(o),([o,E])=>t(E,[...r,o]));return O(t(e,[]),n=>{if(n._tag==="Some")return n.value;throw new Error("unreachable: stream end handled as success")})}var k=1,I=class e{constructor(t){this.env=t;this.id=k++;}id;closed=false;children=new Set;subScopes=new Set;finalizers=[];addFinalizer(t){if(this.closed)throw new Error("Trying to add finalizer to closed scope");this.finalizers.push(t);}subScope(){if(this.closed)throw new Error("Scope closed");let t=new e(this.env);return this.subScopes.add(t),t}fork(t,n){if(this.closed)throw new Error("Scope closed");let r=c(t,n);return this.children.add(r),r.join(()=>{this.children.delete(r);}),r}close(t={_tag:"Success",value:void 0}){if(!this.closed){this.closed=true;for(let n of this.children)n.interrupt();for(let n of this.subScopes)n.close(t);for(;this.finalizers.length>0;){let r=this.finalizers.pop()(t);c(r,this.env);}this.children.clear(),this.subScopes.clear();}}isClosed(){return this.closed}};function ue(e){let t=new I({});try{return e(t)}finally{t.close();}}function Se(){let e=false,t=new Set;return {isCancelled:()=>e,onCancel:r=>{if(e){try{r();}catch{}return ()=>{}}return t.add(r),()=>{t.delete(r);}},cancel:()=>{if(!e){e=true;for(let r of t)try{r();}catch{}t.clear();}}}}function fe(e,t){return e.onCancel(()=>t.abort())}export{I as Scope,Y as catchAll,le as collectStream,d as concatStream,F as emitStream,w as emptyStream,$ as end,u as fail,_ as flatMap,v as flattenStream,ie as foreachStream,pe as fromArray,g as fromPull,fe as linkAbortController,Se as makeCancelToken,A as map,O as mapError,m as mapStream,l as none,x as orElseOptional,se as rangeStream,y as some,Z as succeed,X as sync,i as uncons,ue as withScope,b as zip};
1
+ import {a,f,k as k$1,j,c,e,g as g$1,r,i}from'./chunk-JLFYFKQ2.mjs';export{p as RuntimeFiber,n as Scheduler,l as acquireRelease,i as async,b as asyncCatchAll,f as asyncFail,k as asyncFlatMap,a as asyncFold,m as asyncInterruptible,j as asyncMap,c as asyncMapError,e as asyncSucceed,g as asyncSync,h as asyncTotal,r as fork,q as from,v as fromCallback,u as fromPromise,x as fromPromiseAbortable,o as globalScheduler,t as toPromise,w as tryPromiseAbortable,d as unit,s as unsafeRunAsync}from'./chunk-JLFYFKQ2.mjs';var S={_tag:"None"},b=e=>({_tag:"Some",value:e});var k=e$1=>e(e$1),_=e=>f(e),Ee=e=>g$1(r=>e(r)),g=(e,r)=>j(e,r),N=(e,r)=>k$1(e,t=>r(t)),w=(e,r)=>c(e,r),ie=(e$1,r)=>a(e$1,t=>r(t),t=>e(t));function C(e$1,r){return a(e$1,t=>t._tag==="Some"?f(t):r(),t=>e(t))}var pe=()=>_(S);function Ae(){let e=false,r=new Set;return {isCancelled:()=>e,onCancel:n=>{if(e){try{n();}catch{}return ()=>{}}return r.add(n),()=>{r.delete(n);}},cancel:()=>{if(!e){e=true;for(let n of r)try{n();}catch{}r.clear();}}}}function Re(e,r){return e.onCancel(()=>r.abort())}var H=1,x=class e{constructor(r){this.env=r;this.id=H++;}id;closed=false;children=new Set;subScopes=new Set;finalizers=[];addFinalizer(r){if(this.closed)throw new Error("Trying to add finalizer to closed scope");this.finalizers.push(r);}subScope(){if(this.closed)throw new Error("Scope closed");let r=new e(this.env);return this.subScopes.add(r),r}fork(r$1,t){if(this.closed)throw new Error("Scope closed");let n=r(r$1,t);return this.children.add(n),n.join(()=>{this.children.delete(n);}),n}close(r$1={_tag:"Success",value:void 0}){if(!this.closed){for(this.closed=true,this.children.forEach(t=>t.interrupt()),this.subScopes.forEach(t=>t.close(r$1));this.finalizers.length>0;){let n=this.finalizers.pop()(r$1);r(n,this.env);}this.children.clear(),this.subScopes.clear();}}isClosed(){return this.closed}};function de(e){let r=new x({});try{return e(r)}finally{r.close();}}function T(e,r,t,n,o){return i((a,c)=>{let E=t.subScope(),s=false,R=E.fork(e,a),d=E.fork(r,a),m=u=>{E.fork(u,a).join(f=>{E.close(f),c(f);});};R.join(u=>{s||(s=true,m(n(u,d,E)));}),d.join(u=>{s||(s=true,m(o(u,R,E)));});})}var P=e=>e._tag==="None"?S:b(e.value),Z=e=>({_tag:"FromPull",pull:e}),we=(e,r,t=true)=>({_tag:"Merge",left:e,right:r,flip:t}),$=()=>({_tag:"Empty"}),W=e=>({_tag:"Emit",value:e}),F=(e,r)=>({_tag:"Concat",left:e,right:r}),M=e=>({_tag:"Flatten",stream:e});function L(e$1,r,t,n,o){return (a,c,E)=>{if(console.log(`[mergePull#${o}] winner=${e$1} exit=${a._tag}`),a._tag==="Failure"&&console.log(`[mergePull#${o}] failure error=`,a.error),a._tag==="Success"&&console.log(`[mergePull#${o}] success -> interrupt other`),a._tag==="Success"){let[d,m]=a.value;c.interrupt();let u=Z(e$1==="L"?v(m,t,!n,o):v(r,m,!n,o));return e([d,u])}let s=a.error;if(typeof s=="object"&&s!==null&&s._tag==="Interrupted")return f(s);let R=s;return R._tag==="None"?l(e$1==="L"?t:r):f(R)}}function v(e,r,t,n){return i((o,a)=>{let c=++n;console.log(`[mergePull#${c}] start flip=${t}`);let E=new x(o);console.log(`[mergePull#${c}] built pulls`);let s=l(e),R=l(r);console.log(`[mergePull#${c}] built pulls`);let d=L("L",e,r,t,c),m=L("R",e,r,t,c);console.log(`[mergePull#${c}] calling raceWith`);let u=T(s,R,E,d,m);console.log(`[mergePull#${c}] forking handler`),E.fork(u,o).join(f=>{console.log(`[mergePull#${c}] handler joined exit=${f._tag}`),E.close(f),console.log(`[mergePull#${c}] scope closed, calling cb`),a(f);});})}function Ce(e,r){return Z(v(e,r,true,0))}function l(e){switch(e._tag){case "Empty":return _(S);case "Emit":return g(w(e.value,r=>b(r)),r=>[r,$()]);case "FromPull":return console.log("[uncons] FromPull"),e.pull;case "Concat":return C(g(l(e.left),([r,t])=>[r,F(t,e.right)]),()=>l(e.right));case "Flatten":return N(l(e.stream),([r,t])=>C(g(l(r),([n,o])=>[n,F(o,M(t))]),()=>l(M(t))));case "Merge":return console.log("[makeMergePull] defined"),v(e.left,e.right,e.flip,0)}}function h(e,r){switch(e._tag){case "Empty":return $();case "Emit":return W(g(e.value,r));case "FromPull":return Z(g(e.pull,([t,n])=>[r(t),h(n,r)]));case "Concat":return F(h(e.left,r),h(e.right,r));case "Flatten":{let t=h(e.stream,n=>h(n,r));return M(t)}}}function Pe(e$1,r){let t=n=>Z(n>r?f(S):e([n,t(n+1)]));return t(e$1)}function D(e$1,r){let t=a(c(l(e$1),n=>P(n)),n=>f(n),([n,o])=>a(c(l(r),a=>P(a)),a=>f(a),([a,c])=>e([[n,a],D(o,c)])));return Z(t)}function Me(e$1,r){let t=n=>a(c(l(n),o=>P(o)),o=>o._tag==="None"?e(void 0):f(o),([o,a])=>k$1(c(r(o),c=>b(c)),()=>t(a)));return a(t(e$1),n=>n._tag==="None"?e(void 0):f(n.value),()=>e(void 0))}function $e(e){let r=$();for(let t=e.length-1;t>=0;t--){let n=W(k(e[t]));r=F(n,r);}return r}function je(e){let r=(t,n)=>a(l(t),o=>o._tag==="None"?k(n):_(o),([o,a])=>r(a,[...n,o]));return w(r(e,[]),t=>{if(t._tag==="Some")return t.value;throw new Error("unreachable: stream end handled as success")})}export{x as Scope,ie as catchAll,je as collectStream,F as concatStream,W as emitStream,$ as emptyStream,pe as end,_ as fail,N as flatMap,M as flattenStream,Me as foreachStream,$e as fromArray,Z as fromPull,Re as linkAbortController,Ae as makeCancelToken,g as map,w as mapError,h as mapStream,Ce as merge,we as mergeStream,S as none,C as orElseOptional,Pe as rangeStream,b as some,k as succeed,Ee as sync,l as uncons,de as withScope,D as zip};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "brass-runtime",
3
- "version": "1.4.3",
3
+ "version": "1.4.5",
4
4
  "description": "Effect runtime utilities for TypeScript",
5
5
  "license": "ISC",
6
6
  "author": "",
@@ -1 +0,0 @@
1
- 'use strict';var h=class{queue=[];flushing=false;requested=false;schedule(e,t="anonymous"){if(console.log("[Scheduler.schedule] typeof task =",typeof e,"tag=",t),typeof e!="function"){console.error("[Scheduler.schedule] NON-FUNCTION TASK!",{tag:t,task:e});return}this.queue.push({tag:t,task:e}),this.requestFlush(),console.log("SCHEDULER",{flushing:this.flushing,q:this.queue.length,next:this.queue[0]?.tag,head:this.queue.slice(0,5).map(r=>r.tag)});}requestFlush(){console.log("requestFlush",{flushing:this.flushing,requested:this.requested,q:this.queue.length}),!this.flushing&&(this.requested||(this.requested=true,queueMicrotask(()=>{console.log(">> microtask fired",{flushing:this.flushing,requested:this.requested,q:this.queue.length}),this.flush();})));}flush(){if(console.log("FLUSH enter",{flushing:this.flushing,requested:this.requested,q:this.queue.length}),!this.flushing){this.flushing=true,this.requested=false;try{for(;this.queue.length>0;){let e=this.queue.shift();console.log("[flush] dequeued",{tag:e.tag,typeofTask:typeof e.task});try{console.log("TASK typeof",typeof e.task),e.task();}catch(t){console.error("[flush] task threw",t);}}}finally{this.flushing=false,console.log("FLUSH exit",{requested:this.requested,q:this.queue.length}),this.queue.length>0&&this.requestFlush();}}}},d=new h;var E=1,A=class{constructor(e,t,r){this.scheduler=r;this.id=E++,this.current=e,this.env=t;}id;closing=null;finishing=false;statusValue="Running";interrupted=false;result=null;joiners=[];current;env;stack=[];fiberFinalizers=[];scheduled=false;finalizersDrained=false;blockedOnAsync=false;addFinalizer(e){this.fiberFinalizers.push(e);}status(){return this.statusValue}join(e){this.result!=null?e(this.result):this.joiners.push(e);}interrupt(){this.result==null&&(this.interrupted||(this.interrupted=true,this.blockedOnAsync=false,this.schedule("interrupt-step")));}schedule(e="step"){console.log("[fiber.schedule]",{fiber:this.id,tag:e,schedulerCtor:this.scheduler?.constructor?.name,schedulerScheduleType:typeof this.scheduler?.schedule}),this.result==null&&(this.scheduled||(this.scheduled=true,this.scheduler.schedule(()=>{console.log("[fiber.task] running",this.id),this.scheduled=false,this.step();},`fiber#${this.id}.${e}`)));}runFinalizersOnce(e){if(!this.finalizersDrained)for(this.finalizersDrained=true;this.fiberFinalizers.length>0;){let t=this.fiberFinalizers.pop();try{t(e);}catch{}}}notify(e){if(this.result==null&&this.closing==null){this.finishing=true,this.closing=e,this.runFinalizersOnce(e),this.statusValue=this.interrupted?"Interrupted":"Done",this.result=e;for(let t of this.joiners)t(e);this.joiners.length=0;}}onSuccess(e){let t=this.stack.pop();if(!t){this.notify({_tag:"Success",value:e});return}this.current=t._tag==="SuccessCont"?t.k(e):t.onSuccess(e);}onFailure(e){for(;this.stack.length>0;){let t=this.stack.pop();if(t._tag==="FoldCont"){this.current=t.onFailure(e);return}}this.notify({_tag:"Failure",error:e});}step(){if(console.log("[fiber.step] enter",{fiber:this.id,current:this.current?._tag,result:this.result!=null,blockedOnAsync:this.blockedOnAsync,interrupted:this.interrupted,closing:this.closing!=null,finishing:this.finishing,stack:this.stack.length}),this.result!=null){console.log("[fiber.step] early-exit: already has result",{fiber:this.id});return}if(this.blockedOnAsync){console.log("[fiber.step] early-exit: blockedOnAsync",{fiber:this.id});return}if(this.interrupted&&this.closing==null){console.log("[fiber.step] interrupted: failing now",{fiber:this.id}),this.notify({_tag:"Failure",error:{_tag:"Interrupted"}});return}let e=this.current;switch(e._tag){case "Succeed":{console.log("[fiber.step] Succeed",{fiber:this.id}),this.onSuccess(e.value);return}case "Fail":{console.log("[fiber.step] Fail",{fiber:this.id}),this.onFailure(e.error);return}case "Sync":{console.log("[fiber.step] Sync",{fiber:this.id});try{let t=e.thunk(this.env);console.log("[fiber.step] Sync success",{fiber:this.id}),this.onSuccess(t);}catch(t){console.log("[fiber.step] Sync threw",{fiber:this.id,e:t}),this.onFailure(t);}return}case "FlatMap":{console.log("[fiber.step] FlatMap push cont",{fiber:this.id}),this.stack.push({_tag:"SuccessCont",k:e.andThen}),this.current=e.first;return}case "Fold":{console.log("[fiber.step] Fold push cont",{fiber:this.id}),this.stack.push({_tag:"FoldCont",onFailure:e.onFailure,onSuccess:e.onSuccess}),this.current=e.first;return}case "Async":{if(this.finishing)return;this.blockedOnAsync=true;let t=false,r=o=>{if(this.blockedOnAsync=false,!(this.result!=null||this.closing!=null)){if(this.interrupted){this.onFailure({_tag:"Interrupted"});return}o._tag==="Success"?this.onSuccess(o.value):this.onFailure(o.error),this.schedule("async-resume");}},i=o=>{t||(t=true,this.scheduler.schedule(()=>r(o),`fiber#${this.id}.async-resume`));},s=e.register(this.env,i);typeof s=="function"&&this.addFinalizer(()=>{t=true;try{s();}catch{}});return}}}};function f(n,e,t=d){let r=new A(n,e,t);return r.schedule("initial-step"),r}function y(n,e,t){return {_tag:"Fold",first:n,onFailure:e,onSuccess:t}}function q(n,e){return y(n,t=>e(t),t=>l(t))}function w(n,e){return y(n,t=>b(e(t)),t=>l(t))}function P(n){return c((e,t)=>{let r=false,i=a=>{r||(r=true,t(a));},s=a=>i({_tag:"Failure",error:a instanceof Error?a:new Error(String(a))}),o=a=>i({_tag:"Success",value:a});try{typeof n=="function"&&n.length>=1?n((a,u)=>a?s(a):o(u)):n().then(o,s);}catch(a){s(a);}})}function I(){return p(()=>{})}var l=n=>({_tag:"Succeed",value:n}),b=n=>({_tag:"Fail",error:n}),p=n=>({_tag:"Sync",thunk:n}),C=n=>p(()=>n()),c=n=>({_tag:"Async",register:n});function B(n,e){return g(n,t=>l(e(t)))}function g(n,e){return {_tag:"FlatMap",first:n,andThen:e}}function T(n,e){return new Promise((t,r)=>{f(n,e).join(s=>{let o=s;o._tag==="Success"?t(o.value):r(o.error);});})}function z(n,e){return c((t,r)=>{n(t).then(i=>r({_tag:"Success",value:i})).catch(i=>r({_tag:"Failure",error:e(i)}));})}function j(n){return c((e,t)=>{let r=false,i=s=>{r||(r=true,t(s));};try{n((s,o)=>{i(s?{_tag:"Failure",error:s}:{_tag:"Success",value:o});});}catch(s){i({_tag:"Failure",error:s instanceof Error?s:new Error(String(s))});}})}var v=n=>typeof n=="object"&&n!==null&&"name"in n&&n.name==="AbortError";function O(n){return R((t,r)=>n.length===1?n(r):n(t,r),t=>v(t)?{_tag:"Abort"}:{_tag:"PromiseRejected",reason:t})}function R(n,e){return c((t,r)=>{let i=new AbortController,s=false,o=a=>{s||(s=true,r(a));};try{(n.length===1?n(i.signal):n(t,i.signal)).then(u=>o({_tag:"Success",value:u})).catch(u=>o({_tag:"Failure",error:e(u)}));}catch(a){o({_tag:"Failure",error:e(a)});}return ()=>{s=true,i.abort();}})}function M(n,e,t){return g(n,r=>(t.addFinalizer(i=>e(r,i)),l(r)))}function N(n){return c(n)}exports.a=h;exports.b=d;exports.c=f;exports.d=y;exports.e=q;exports.f=w;exports.g=P;exports.h=I;exports.i=l;exports.j=b;exports.k=p;exports.l=C;exports.m=c;exports.n=B;exports.o=g;exports.p=T;exports.q=z;exports.r=j;exports.s=O;exports.t=R;exports.u=M;exports.v=N;
@@ -1 +0,0 @@
1
- var h=class{queue=[];flushing=false;requested=false;schedule(e,t="anonymous"){if(console.log("[Scheduler.schedule] typeof task =",typeof e,"tag=",t),typeof e!="function"){console.error("[Scheduler.schedule] NON-FUNCTION TASK!",{tag:t,task:e});return}this.queue.push({tag:t,task:e}),this.requestFlush(),console.log("SCHEDULER",{flushing:this.flushing,q:this.queue.length,next:this.queue[0]?.tag,head:this.queue.slice(0,5).map(r=>r.tag)});}requestFlush(){console.log("requestFlush",{flushing:this.flushing,requested:this.requested,q:this.queue.length}),!this.flushing&&(this.requested||(this.requested=true,queueMicrotask(()=>{console.log(">> microtask fired",{flushing:this.flushing,requested:this.requested,q:this.queue.length}),this.flush();})));}flush(){if(console.log("FLUSH enter",{flushing:this.flushing,requested:this.requested,q:this.queue.length}),!this.flushing){this.flushing=true,this.requested=false;try{for(;this.queue.length>0;){let e=this.queue.shift();console.log("[flush] dequeued",{tag:e.tag,typeofTask:typeof e.task});try{console.log("TASK typeof",typeof e.task),e.task();}catch(t){console.error("[flush] task threw",t);}}}finally{this.flushing=false,console.log("FLUSH exit",{requested:this.requested,q:this.queue.length}),this.queue.length>0&&this.requestFlush();}}}},d=new h;var E=1,A=class{constructor(e,t,r){this.scheduler=r;this.id=E++,this.current=e,this.env=t;}id;closing=null;finishing=false;statusValue="Running";interrupted=false;result=null;joiners=[];current;env;stack=[];fiberFinalizers=[];scheduled=false;finalizersDrained=false;blockedOnAsync=false;addFinalizer(e){this.fiberFinalizers.push(e);}status(){return this.statusValue}join(e){this.result!=null?e(this.result):this.joiners.push(e);}interrupt(){this.result==null&&(this.interrupted||(this.interrupted=true,this.blockedOnAsync=false,this.schedule("interrupt-step")));}schedule(e="step"){console.log("[fiber.schedule]",{fiber:this.id,tag:e,schedulerCtor:this.scheduler?.constructor?.name,schedulerScheduleType:typeof this.scheduler?.schedule}),this.result==null&&(this.scheduled||(this.scheduled=true,this.scheduler.schedule(()=>{console.log("[fiber.task] running",this.id),this.scheduled=false,this.step();},`fiber#${this.id}.${e}`)));}runFinalizersOnce(e){if(!this.finalizersDrained)for(this.finalizersDrained=true;this.fiberFinalizers.length>0;){let t=this.fiberFinalizers.pop();try{t(e);}catch{}}}notify(e){if(this.result==null&&this.closing==null){this.finishing=true,this.closing=e,this.runFinalizersOnce(e),this.statusValue=this.interrupted?"Interrupted":"Done",this.result=e;for(let t of this.joiners)t(e);this.joiners.length=0;}}onSuccess(e){let t=this.stack.pop();if(!t){this.notify({_tag:"Success",value:e});return}this.current=t._tag==="SuccessCont"?t.k(e):t.onSuccess(e);}onFailure(e){for(;this.stack.length>0;){let t=this.stack.pop();if(t._tag==="FoldCont"){this.current=t.onFailure(e);return}}this.notify({_tag:"Failure",error:e});}step(){if(console.log("[fiber.step] enter",{fiber:this.id,current:this.current?._tag,result:this.result!=null,blockedOnAsync:this.blockedOnAsync,interrupted:this.interrupted,closing:this.closing!=null,finishing:this.finishing,stack:this.stack.length}),this.result!=null){console.log("[fiber.step] early-exit: already has result",{fiber:this.id});return}if(this.blockedOnAsync){console.log("[fiber.step] early-exit: blockedOnAsync",{fiber:this.id});return}if(this.interrupted&&this.closing==null){console.log("[fiber.step] interrupted: failing now",{fiber:this.id}),this.notify({_tag:"Failure",error:{_tag:"Interrupted"}});return}let e=this.current;switch(e._tag){case "Succeed":{console.log("[fiber.step] Succeed",{fiber:this.id}),this.onSuccess(e.value);return}case "Fail":{console.log("[fiber.step] Fail",{fiber:this.id}),this.onFailure(e.error);return}case "Sync":{console.log("[fiber.step] Sync",{fiber:this.id});try{let t=e.thunk(this.env);console.log("[fiber.step] Sync success",{fiber:this.id}),this.onSuccess(t);}catch(t){console.log("[fiber.step] Sync threw",{fiber:this.id,e:t}),this.onFailure(t);}return}case "FlatMap":{console.log("[fiber.step] FlatMap push cont",{fiber:this.id}),this.stack.push({_tag:"SuccessCont",k:e.andThen}),this.current=e.first;return}case "Fold":{console.log("[fiber.step] Fold push cont",{fiber:this.id}),this.stack.push({_tag:"FoldCont",onFailure:e.onFailure,onSuccess:e.onSuccess}),this.current=e.first;return}case "Async":{if(this.finishing)return;this.blockedOnAsync=true;let t=false,r=o=>{if(this.blockedOnAsync=false,!(this.result!=null||this.closing!=null)){if(this.interrupted){this.onFailure({_tag:"Interrupted"});return}o._tag==="Success"?this.onSuccess(o.value):this.onFailure(o.error),this.schedule("async-resume");}},i=o=>{t||(t=true,this.scheduler.schedule(()=>r(o),`fiber#${this.id}.async-resume`));},s=e.register(this.env,i);typeof s=="function"&&this.addFinalizer(()=>{t=true;try{s();}catch{}});return}}}};function f(n,e,t=d){let r=new A(n,e,t);return r.schedule("initial-step"),r}function y(n,e,t){return {_tag:"Fold",first:n,onFailure:e,onSuccess:t}}function q(n,e){return y(n,t=>e(t),t=>l(t))}function w(n,e){return y(n,t=>b(e(t)),t=>l(t))}function P(n){return c((e,t)=>{let r=false,i=a=>{r||(r=true,t(a));},s=a=>i({_tag:"Failure",error:a instanceof Error?a:new Error(String(a))}),o=a=>i({_tag:"Success",value:a});try{typeof n=="function"&&n.length>=1?n((a,u)=>a?s(a):o(u)):n().then(o,s);}catch(a){s(a);}})}function I(){return p(()=>{})}var l=n=>({_tag:"Succeed",value:n}),b=n=>({_tag:"Fail",error:n}),p=n=>({_tag:"Sync",thunk:n}),C=n=>p(()=>n()),c=n=>({_tag:"Async",register:n});function B(n,e){return g(n,t=>l(e(t)))}function g(n,e){return {_tag:"FlatMap",first:n,andThen:e}}function T(n,e){return new Promise((t,r)=>{f(n,e).join(s=>{let o=s;o._tag==="Success"?t(o.value):r(o.error);});})}function z(n,e){return c((t,r)=>{n(t).then(i=>r({_tag:"Success",value:i})).catch(i=>r({_tag:"Failure",error:e(i)}));})}function j(n){return c((e,t)=>{let r=false,i=s=>{r||(r=true,t(s));};try{n((s,o)=>{i(s?{_tag:"Failure",error:s}:{_tag:"Success",value:o});});}catch(s){i({_tag:"Failure",error:s instanceof Error?s:new Error(String(s))});}})}var v=n=>typeof n=="object"&&n!==null&&"name"in n&&n.name==="AbortError";function O(n){return R((t,r)=>n.length===1?n(r):n(t,r),t=>v(t)?{_tag:"Abort"}:{_tag:"PromiseRejected",reason:t})}function R(n,e){return c((t,r)=>{let i=new AbortController,s=false,o=a=>{s||(s=true,r(a));};try{(n.length===1?n(i.signal):n(t,i.signal)).then(u=>o({_tag:"Success",value:u})).catch(u=>o({_tag:"Failure",error:e(u)}));}catch(a){o({_tag:"Failure",error:e(a)});}return ()=>{s=true,i.abort();}})}function M(n,e,t){return g(n,r=>(t.addFinalizer(i=>e(r,i)),l(r)))}function N(n){return c(n)}export{h as a,d as b,f as c,y as d,q as e,w as f,P as g,I as h,l as i,b as j,p as k,C as l,c as m,B as n,g as o,T as p,z as q,j as r,O as s,R as t,M as u,N as v};