Skip to content

Commit 9675d87

Browse files
author
Taras Mankovski
committed
✨ Export reducer internals via experimental and label infrastructure effects
Export ReducerContext, Instruction, InstructionQueue, and DelimiterContext through the experimental entry point, enabling external packages to build custom reducers (e.g., for durable execution) without forking Effection. Add description labels to withResolvers() calls in core infrastructure effects (callcc, delimiter, each, future, scope-internal) so that custom reducers can distinguish infrastructure effects from user-facing effects by their description strings.
1 parent 9e6b35a commit 9675d87

7 files changed

Lines changed: 15 additions & 8 deletions

File tree

experimental.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,8 @@
11
export * from "./lib/api.ts";
2+
export {
3+
Reducer,
4+
ReducerContext,
5+
InstructionQueue,
6+
type Instruction,
7+
} from "./lib/reducer.ts";
8+
export { DelimiterContext } from "./lib/delimiter.ts";

lib/callcc.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ export function* callcc<T>(
1111
reject: (error: Error) => Operation<void>,
1212
) => Operation<void>,
1313
): Operation<T> {
14-
let result = withResolvers<Result<T>>();
14+
let result = withResolvers<Result<T>>("await callcc");
1515

1616
let resolve = lift((value: T) => result.resolve(Ok(value)));
1717

lib/delimiter.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ export class Delimiter<T>
1010
implements Operation<Maybe<Result<T>>>, ErrorBoundary {
1111
level = 0;
1212
finalized = false;
13-
future = withResolvers<Maybe<Result<T>>>();
13+
future = withResolvers<Maybe<Result<T>>>("await delimiter");
1414
computed = false;
1515
routine?: Coroutine;
1616
outcome?: Maybe<Result<T>>;

lib/each.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@ export function each<T>(stream: Stream<T, unknown>): Operation<Iterable<T>> {
3737
scope.set(EachStack, []);
3838
}
3939

40-
let done = withResolvers<void>();
41-
let cxt = withResolvers<EachLoop<T>>();
40+
let done = withResolvers<void>("await each done");
41+
let cxt = withResolvers<EachLoop<T>>("await each context");
4242

4343
yield* spawn(function* () {
4444
let subscription = yield* stream;

lib/future.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ export interface FutureWithResolvers<T> {
99
}
1010
export function createFuture<T>(): FutureWithResolvers<T> {
1111
let promise = lazyPromiseWithResolvers<T>();
12-
let operation = withResolvers<T>();
12+
let operation = withResolvers<T>("await future");
1313

1414
let resolve = (value: T) => {
1515
promise.resolve(value);

lib/reducer.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,15 +58,15 @@ export class Reducer {
5858
};
5959
}
6060

61-
type Instruction = [
61+
export type Instruction = [
6262
number,
6363
Coroutine<unknown>,
6464
Result<unknown>,
6565
() => boolean,
6666
"return" | "next",
6767
];
6868

69-
class InstructionQueue extends PriorityQueue<Instruction> {
69+
export class InstructionQueue extends PriorityQueue<Instruction> {
7070
enqueue(instruction: Instruction): void {
7171
let [priority] = instruction;
7272
this.push(priority, instruction);

lib/scope-internal.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ export function buildScopeInternal(
133133
if (destruction) {
134134
return yield* destruction.operation;
135135
}
136-
destruction = withResolvers<void>();
136+
destruction = withResolvers<void>("await destruction");
137137
parent?.expect(Children).delete(scope);
138138
unbind();
139139
let outcome = Ok();

0 commit comments

Comments
 (0)