diff --git a/.changeset/retain-interrupted-start.md b/.changeset/retain-interrupted-start.md new file mode 100644 index 0000000..dcd803e --- /dev/null +++ b/.changeset/retain-interrupted-start.md @@ -0,0 +1,5 @@ +--- +"effect-machine": patch +--- + +Keep an interrupted first `actor.start` until the actor is stopped. A later `start` again returns the first start's interruption and does not run recovery or the startup again. `Effect.cached` drops an interrupted run since effect 4.0.1, so the actor now keeps the first start's exit itself. diff --git a/bun.lock b/bun.lock index e9f4043..434c59d 100644 --- a/bun.lock +++ b/bun.lock @@ -8,8 +8,8 @@ "@changesets/changelog-github": "1.0.1", "@changesets/cli": "3.0.2", "@effect-machine/examples-shared": "file:./examples/shared", - "@effect/atom-react": "4.0.0", - "@effect/atom-solid": "4.0.0", + "@effect/atom-react": "4.1.7", + "@effect/atom-solid": "4.1.7", "@effect/tsgo": "0.47.2", "@solidjs/testing-library": "0.8.10", "@testing-library/react": "16.3.3", @@ -18,7 +18,7 @@ "@types/react-dom": "19.2.7", "@vitejs/plugin-react": "6.1.1", "concurrently": "10.0.5", - "effect": "4.0.0", + "effect": "4.1.7", "effect-bun-test": "0.3.0", "jsdom": "30.0.1", "lefthook": "2.1.12", @@ -136,11 +136,11 @@ "@csstools/css-tokenizer": ["@csstools/css-tokenizer@4.0.0", "", {}, "sha512-QxULHAm7cNu72w97JUNCBFODFaXpbDg+dP8b/oWFAZ2MTRppA3U00Y2L1HqaS4J6yBqxwa/Y3nMBaxVKbB/NsA=="], - "@effect-machine/examples-shared": ["@effect-machine/examples-shared@file:examples/shared", { "dependencies": { "effect": "4.0.0" }, "devDependencies": { "typescript": "7.0.2" } }], + "@effect-machine/examples-shared": ["@effect-machine/examples-shared@file:examples/shared", { "dependencies": { "effect": "4.1.7" }, "devDependencies": { "typescript": "7.0.2" } }], - "@effect/atom-react": ["@effect/atom-react@4.0.0", "", { "peerDependencies": { "effect": "^4.0.0", "react": ">=19.0.0 <20.0.0", "scheduler": ">=0.25.0 <0.28.0" } }, "sha512-VPP2oOjj56iwOpL5aIGbu7Qhb4+1sFNdU16aI5of3JqToqWWX9eJPBfeiPyQ1eTYof1hnNX1auyRiTORSfLT6g=="], + "@effect/atom-react": ["@effect/atom-react@4.1.7", "", { "peerDependencies": { "effect": "^4.1.7", "react": ">=19.0.0 <20.0.0", "scheduler": ">=0.25.0 <0.29.0" } }, "sha512-DDyKohcd4NsdHygwNW2BPzqoR4axSocMOhwQN2rEHfMYKo6EqpRcAsoFRs+rkyHp7YasFcYI8KyasW2sQhvQDQ=="], - "@effect/atom-solid": ["@effect/atom-solid@4.0.0", "", { "peerDependencies": { "effect": "^4.0.0", "solid-js": ">=1.9.14 <2.0.0" } }, "sha512-aiFIXe5DEVzNUm4Z8CVrBaDJNmRIhgGFS2UvCXf+5oIm4hqxIme7ynF/ZpENwPjjaqgckKJPuR519c6+e3GQcg=="], + "@effect/atom-solid": ["@effect/atom-solid@4.1.7", "", { "peerDependencies": { "effect": "^4.1.7", "solid-js": ">=1.9.14 <2.0.0" } }, "sha512-Tgl5AY5+ha3FNQk1BHa+9YwmXNOmdO98bU6f7MZYoOBHhOmyx5HbgSbJLcKcKx3BBuOzfUFdjYcChPu2tTEbwQ=="], "@effect/tsgo": ["@effect/tsgo@0.47.2", "", { "optionalDependencies": { "@effect/tsgo-darwin-arm64": "0.47.2", "@effect/tsgo-darwin-x64": "0.47.2", "@effect/tsgo-linux-arm": "0.47.2", "@effect/tsgo-linux-arm64": "0.47.2", "@effect/tsgo-linux-x64": "0.47.2", "@effect/tsgo-win32-arm64": "0.47.2", "@effect/tsgo-win32-x64": "0.47.2" }, "bin": { "effect-tsgo": "dist/effect-tsgo.cjs" } }, "sha512-mGIelPZhTJg8g+RgiAe7wrB8NLw/lOzPGntAYBBqEJS0/I8ir1/ULKcpFQyuAfPjwkDYrg93KWv1PDGwgsgBIA=="], @@ -506,7 +506,7 @@ "dts-resolver": ["dts-resolver@3.0.0", "", { "peerDependencies": { "oxc-resolver": ">=11.0.0" }, "optionalPeers": ["oxc-resolver"] }, "sha512-1T1f+z+4tl9XD+m+0HBgWoL/nm0bOIffyWaUuUSBlFg/86IWvfx+wjNaO/ybU0AJzG9/Mi5hBUgGV6zCmWEN7Q=="], - "effect": ["effect@4.0.0", "", {}, "sha512-ooc1TG5t+FfzgYnFz2ff6BBKyZ7EwBRVXC7c4RhQUAD6/TZ2gTXXMeb4WX7a19ozQo4J73/QW+S00YAIresoMQ=="], + "effect": ["effect@4.1.7", "", {}, "sha512-8QUe2XO3auHF5r7+bfIDWxyXlLA0sso4Sia1QYP+vrYA7qb3sq1u2eJmhyXGmKc8yZ+TY2SNxPozeMdyKmWing=="], "effect-bun-test": ["effect-bun-test@0.3.0", "", { "peerDependencies": { "bun": "*", "effect": ">=3.19.0" } }, "sha512-P2xZ4HBZg4bFw2ePY4E5UB6EZ2d1L/HO13+KdoprTYFuc8B1uTpdn7V4UU6qyYiYsqTY9DZ1TFB94Ekx2YLA4g=="], diff --git a/examples/core/package.json b/examples/core/package.json index a27c70b..3d41718 100644 --- a/examples/core/package.json +++ b/examples/core/package.json @@ -8,7 +8,7 @@ "gate": "bun run typecheck && bun run test" }, "dependencies": { - "effect": "4.0.0" + "effect": "4.1.7" }, "devDependencies": { "@types/bun": "1.4.0", diff --git a/examples/react/package.json b/examples/react/package.json index 46223a1..ffeb3d7 100644 --- a/examples/react/package.json +++ b/examples/react/package.json @@ -10,8 +10,8 @@ }, "dependencies": { "@effect-machine/examples-shared": "file:../shared", - "@effect/atom-react": "4.0.0", - "effect": "4.0.0", + "@effect/atom-react": "4.1.7", + "effect": "4.1.7", "motion": "13.1.1", "react": "19.2.8", "react-dom": "19.2.8" diff --git a/examples/shared/package.json b/examples/shared/package.json index 2092c26..2c18dce 100644 --- a/examples/shared/package.json +++ b/examples/shared/package.json @@ -10,7 +10,7 @@ "gate": "bun run typecheck" }, "dependencies": { - "effect": "4.0.0" + "effect": "4.1.7" }, "devDependencies": { "typescript": "7.0.2" diff --git a/examples/solid/package.json b/examples/solid/package.json index ffd63cd..0b0c712 100644 --- a/examples/solid/package.json +++ b/examples/solid/package.json @@ -10,8 +10,8 @@ }, "dependencies": { "@effect-machine/examples-shared": "file:../shared", - "@effect/atom-solid": "4.0.0", - "effect": "4.0.0", + "@effect/atom-solid": "4.1.7", + "effect": "4.1.7", "solid-js": "1.9.15", "solid-transition-group": "0.3.0" }, diff --git a/package.json b/package.json index 56aec47..8225129 100644 --- a/package.json +++ b/package.json @@ -55,8 +55,8 @@ "@changesets/changelog-github": "1.0.1", "@changesets/cli": "3.0.2", "@effect-machine/examples-shared": "file:./examples/shared", - "@effect/atom-react": "4.0.0", - "@effect/atom-solid": "4.0.0", + "@effect/atom-react": "4.1.7", + "@effect/atom-solid": "4.1.7", "@effect/tsgo": "0.47.2", "@solidjs/testing-library": "0.8.10", "@testing-library/react": "16.3.3", @@ -65,7 +65,7 @@ "@types/react-dom": "19.2.7", "@vitejs/plugin-react": "6.1.1", "concurrently": "10.0.5", - "effect": "4.0.0", + "effect": "4.1.7", "effect-bun-test": "0.3.0", "jsdom": "30.0.1", "lefthook": "2.1.12", diff --git a/src/actor.ts b/src/actor.ts index eac95d5..c5da379 100644 --- a/src/actor.ts +++ b/src/actor.ts @@ -1364,9 +1364,14 @@ export const createActor = Effect.fn("effect-machine.actor.spawn")(function* < } } }); - // oxlint-disable-next-line effect/noPerCallCacheConstruction -- Actor allocation owns one startup result for this actor. - const start = yield* Effect.cached( - startupLock + // The first start's exit, interruption included, answers every later start. Effect.cached + // drops an interrupted run since effect 4.0.1, so the actor holds the exit itself. + const startExit = Deferred.makeUnsafe(); + let startRequested = false; + const start = Effect.suspend(() => { + if (startRequested) return Deferred.await(startExit); + startRequested = true; + return startupLock .withPermit( Effect.gen(function* () { if (stopRequested) return undefined; @@ -1380,8 +1385,9 @@ export const createActor = Effect.fn("effect-machine.actor.spawn")(function* < return Fiber.join(starting); }), Effect.provide(serviceContext), - ), - ); + Effect.onExit((exit) => Deferred.done(startExit, exit)), + ); + }); return buildActorRefCore(cell, stop, start, serviceContext); });