@effectionx/effect-ts 0.1.0 → 0.1.1
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.
- package/effect.test.ts +12 -8
- package/package.json +3 -2
package/effect.test.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { describe, it } from "@effectionx/bdd";
|
|
2
2
|
import { Context, Effect, Exit, Fiber, Layer } from "effect";
|
|
3
|
-
import { call, scoped, sleep, spawn, suspend } from "effection";
|
|
3
|
+
import { call, scoped, sleep, spawn, suspend, withResolvers } from "effection";
|
|
4
4
|
import { expect } from "expect";
|
|
5
5
|
|
|
6
6
|
import {
|
|
@@ -157,7 +157,8 @@ describe("@effectionx/effect-ts", () => {
|
|
|
157
157
|
describe("cancellation", () => {
|
|
158
158
|
it("interrupts Effect when Effection task is halted", function* () {
|
|
159
159
|
let finalizerRan = false;
|
|
160
|
-
|
|
160
|
+
const { resolve: effectReady, operation: waitForEffectReady } =
|
|
161
|
+
withResolvers<void>();
|
|
161
162
|
|
|
162
163
|
// Run in a nested scope so we can control when it ends
|
|
163
164
|
yield* scoped(function* () {
|
|
@@ -167,23 +168,23 @@ describe("@effectionx/effect-ts", () => {
|
|
|
167
168
|
yield* spawn(function* () {
|
|
168
169
|
yield* runtime.run(
|
|
169
170
|
Effect.gen(function* () {
|
|
170
|
-
effectStarted = true;
|
|
171
171
|
yield* Effect.addFinalizer(() =>
|
|
172
172
|
Effect.sync(() => {
|
|
173
173
|
finalizerRan = true;
|
|
174
174
|
}),
|
|
175
175
|
);
|
|
176
|
+
// Signal after finalizer is registered
|
|
177
|
+
effectReady();
|
|
176
178
|
yield* Effect.sleep("10 seconds");
|
|
177
179
|
}).pipe(Effect.scoped),
|
|
178
180
|
);
|
|
179
181
|
});
|
|
180
182
|
|
|
181
|
-
//
|
|
182
|
-
yield*
|
|
183
|
+
// Wait for the effect to register finalizer before scope ends
|
|
184
|
+
yield* waitForEffectReady;
|
|
183
185
|
});
|
|
184
186
|
|
|
185
187
|
// After the scoped block completes, the finalizer should have run
|
|
186
|
-
expect(effectStarted).toEqual(true);
|
|
187
188
|
expect(finalizerRan).toEqual(true);
|
|
188
189
|
});
|
|
189
190
|
});
|
|
@@ -417,6 +418,8 @@ describe("@effectionx/effect-ts", () => {
|
|
|
417
418
|
describe("resource cleanup", () => {
|
|
418
419
|
it("cleans up Effect resources when Effection scope halts", function* () {
|
|
419
420
|
const cleanupOrder: string[] = [];
|
|
421
|
+
const { resolve: resourceAcquired, operation: waitForAcquire } =
|
|
422
|
+
withResolvers<void>();
|
|
420
423
|
|
|
421
424
|
yield* scoped(function* () {
|
|
422
425
|
const runtime = yield* makeEffectRuntime();
|
|
@@ -427,6 +430,7 @@ describe("@effectionx/effect-ts", () => {
|
|
|
427
430
|
yield* Effect.acquireRelease(
|
|
428
431
|
Effect.sync(() => {
|
|
429
432
|
cleanupOrder.push("acquired");
|
|
433
|
+
resourceAcquired();
|
|
430
434
|
}),
|
|
431
435
|
() =>
|
|
432
436
|
Effect.sync(() => {
|
|
@@ -439,8 +443,8 @@ describe("@effectionx/effect-ts", () => {
|
|
|
439
443
|
);
|
|
440
444
|
});
|
|
441
445
|
|
|
442
|
-
|
|
443
|
-
|
|
446
|
+
// Wait for the resource to be acquired before scope ends
|
|
447
|
+
yield* waitForAcquire;
|
|
444
448
|
});
|
|
445
449
|
|
|
446
450
|
// After scoped block completes, cleanup should have happened
|
package/package.json
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@effectionx/effect-ts",
|
|
3
|
-
"
|
|
3
|
+
"description": "Bidirectional interop between Effect-TS and Effection",
|
|
4
|
+
"version": "0.1.1",
|
|
4
5
|
"type": "module",
|
|
5
6
|
"main": "./dist/mod.js",
|
|
6
7
|
"types": "./dist/mod.d.ts",
|
|
@@ -16,7 +17,7 @@
|
|
|
16
17
|
},
|
|
17
18
|
"devDependencies": {
|
|
18
19
|
"effect": "^3",
|
|
19
|
-
"@effectionx/bdd": "0.4.
|
|
20
|
+
"@effectionx/bdd": "0.4.2"
|
|
20
21
|
},
|
|
21
22
|
"license": "MIT",
|
|
22
23
|
"author": "engineering@frontside.com",
|