chore: generate
This commit is contained in:
@@ -82,31 +82,38 @@ The `InstanceState.make` init callback receives a `Scope`, so you can use `Effec
|
|||||||
- **Subscriptions**: Yield `Bus.Service` at the layer level, then use `Stream` + `forkScoped` inside the init closure. The fiber is automatically interrupted when the instance scope closes:
|
- **Subscriptions**: Yield `Bus.Service` at the layer level, then use `Stream` + `forkScoped` inside the init closure. The fiber is automatically interrupted when the instance scope closes:
|
||||||
|
|
||||||
```ts
|
```ts
|
||||||
const bus = yield* Bus.Service
|
const bus = yield * Bus.Service
|
||||||
|
|
||||||
const cache = yield* InstanceState.make<State>(
|
const cache =
|
||||||
Effect.fn("Foo.state")(function* (ctx) {
|
yield *
|
||||||
// ... load state ...
|
InstanceState.make<State>(
|
||||||
|
Effect.fn("Foo.state")(function* (ctx) {
|
||||||
|
// ... load state ...
|
||||||
|
|
||||||
yield* bus
|
yield* bus.subscribeAll().pipe(
|
||||||
.subscribeAll()
|
Stream.runForEach((event) =>
|
||||||
.pipe(
|
Effect.sync(() => {
|
||||||
Stream.runForEach((event) => Effect.sync(() => { /* handle */ })),
|
/* handle */
|
||||||
|
}),
|
||||||
|
),
|
||||||
Effect.forkScoped,
|
Effect.forkScoped,
|
||||||
)
|
)
|
||||||
|
|
||||||
return { /* state */ }
|
return {
|
||||||
}),
|
/* state */
|
||||||
)
|
}
|
||||||
|
}),
|
||||||
|
)
|
||||||
```
|
```
|
||||||
|
|
||||||
- **Resource cleanup**: Use `Effect.acquireRelease` or `Effect.addFinalizer` for resources that need teardown (native watchers, process handles, etc.):
|
- **Resource cleanup**: Use `Effect.acquireRelease` or `Effect.addFinalizer` for resources that need teardown (native watchers, process handles, etc.):
|
||||||
|
|
||||||
```ts
|
```ts
|
||||||
yield* Effect.acquireRelease(
|
yield *
|
||||||
Effect.sync(() => nativeAddon.watch(dir)),
|
Effect.acquireRelease(
|
||||||
(watcher) => Effect.sync(() => watcher.close()),
|
Effect.sync(() => nativeAddon.watch(dir)),
|
||||||
)
|
(watcher) => Effect.sync(() => watcher.close()),
|
||||||
|
)
|
||||||
```
|
```
|
||||||
|
|
||||||
- **Background fibers**: Use `Effect.forkScoped` — the fiber is interrupted on disposal.
|
- **Background fibers**: Use `Effect.forkScoped` — the fiber is interrupted on disposal.
|
||||||
|
|||||||
@@ -404,15 +404,11 @@ export namespace File {
|
|||||||
s.cache = next
|
s.cache = next
|
||||||
})
|
})
|
||||||
|
|
||||||
let cachedScan = yield* Effect.cached(
|
let cachedScan = yield* Effect.cached(scan().pipe(Effect.catchCause(() => Effect.void)))
|
||||||
scan().pipe(Effect.catchCause(() => Effect.void)),
|
|
||||||
)
|
|
||||||
|
|
||||||
const ensure = Effect.fn("File.ensure")(function* () {
|
const ensure = Effect.fn("File.ensure")(function* () {
|
||||||
yield* cachedScan
|
yield* cachedScan
|
||||||
cachedScan = yield* Effect.cached(
|
cachedScan = yield* Effect.cached(scan().pipe(Effect.catchCause(() => Effect.void)))
|
||||||
scan().pipe(Effect.catchCause(() => Effect.void)),
|
|
||||||
)
|
|
||||||
})
|
})
|
||||||
|
|
||||||
const init = Effect.fn("File.init")(function* () {
|
const init = Effect.fn("File.init")(function* () {
|
||||||
|
|||||||
@@ -149,18 +149,16 @@ export namespace Plugin {
|
|||||||
})
|
})
|
||||||
|
|
||||||
// Subscribe to bus events, fiber interrupted when scope closes
|
// Subscribe to bus events, fiber interrupted when scope closes
|
||||||
yield* bus
|
yield* bus.subscribeAll().pipe(
|
||||||
.subscribeAll()
|
Stream.runForEach((input) =>
|
||||||
.pipe(
|
Effect.sync(() => {
|
||||||
Stream.runForEach((input) =>
|
for (const hook of hooks) {
|
||||||
Effect.sync(() => {
|
hook["event"]?.({ event: input as any })
|
||||||
for (const hook of hooks) {
|
}
|
||||||
hook["event"]?.({ event: input as any })
|
}),
|
||||||
}
|
),
|
||||||
}),
|
Effect.forkScoped,
|
||||||
),
|
)
|
||||||
Effect.forkScoped,
|
|
||||||
)
|
|
||||||
|
|
||||||
return { hooks }
|
return { hooks }
|
||||||
}),
|
}),
|
||||||
|
|||||||
@@ -159,22 +159,20 @@ export namespace Vcs {
|
|||||||
const value = { current, root }
|
const value = { current, root }
|
||||||
log.info("initialized", { branch: value.current, default_branch: value.root?.name })
|
log.info("initialized", { branch: value.current, default_branch: value.root?.name })
|
||||||
|
|
||||||
yield* bus
|
yield* bus.subscribe(FileWatcher.Event.Updated).pipe(
|
||||||
.subscribe(FileWatcher.Event.Updated)
|
Stream.filter((evt) => evt.properties.file.endsWith("HEAD")),
|
||||||
.pipe(
|
Stream.runForEach((_evt) =>
|
||||||
Stream.filter((evt) => evt.properties.file.endsWith("HEAD")),
|
Effect.gen(function* () {
|
||||||
Stream.runForEach((_evt) =>
|
const next = yield* Effect.promise(() => get())
|
||||||
Effect.gen(function* () {
|
if (next !== value.current) {
|
||||||
const next = yield* Effect.promise(() => get())
|
log.info("branch changed", { from: value.current, to: next })
|
||||||
if (next !== value.current) {
|
value.current = next
|
||||||
log.info("branch changed", { from: value.current, to: next })
|
yield* bus.publish(Event.BranchUpdated, { branch: next })
|
||||||
value.current = next
|
}
|
||||||
yield* bus.publish(Event.BranchUpdated, { branch: next })
|
}),
|
||||||
}
|
),
|
||||||
}),
|
Effect.forkScoped,
|
||||||
),
|
)
|
||||||
Effect.forkScoped,
|
|
||||||
)
|
|
||||||
|
|
||||||
return value
|
return value
|
||||||
}),
|
}),
|
||||||
|
|||||||
@@ -162,10 +162,7 @@ describe("Vcs diff", () => {
|
|||||||
await $`git worktree add -b feature/test ${dir} HEAD`.cwd(tmp.path).quiet()
|
await $`git worktree add -b feature/test ${dir} HEAD`.cwd(tmp.path).quiet()
|
||||||
|
|
||||||
await withVcsOnly(dir, async () => {
|
await withVcsOnly(dir, async () => {
|
||||||
const [branch, base] = await Promise.all([
|
const [branch, base] = await Promise.all([Vcs.branch(), Vcs.defaultBranch()])
|
||||||
Vcs.branch(),
|
|
||||||
Vcs.defaultBranch(),
|
|
||||||
])
|
|
||||||
expect(branch).toBe("feature/test")
|
expect(branch).toBe("feature/test")
|
||||||
expect(base).toBe("main")
|
expect(base).toBe("main")
|
||||||
})
|
})
|
||||||
|
|||||||
Reference in New Issue
Block a user