Skip to content

Commit

Permalink
ensure metrics is interruptible
Browse files Browse the repository at this point in the history
  • Loading branch information
tim-smart committed Feb 15, 2024
1 parent b8adecb commit bb3a01d
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 30 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -135,15 +135,15 @@
"devDependencies": {
"@changesets/changelog-github": "^0.5.0",
"@changesets/cli": "^2.27.1",
"@effect/experimental": "^0.9.10",
"@effect/experimental": "^0.9.11",
"@effect/language-service": "^0.1.0",
"@types/mocha": "^10.0.6",
"@types/node": "~20.11.17",
"@types/vscode": "^1.84.0",
"@types/ws": "^8.5.10",
"@vscode/test-electron": "^2.3.9",
"@vscode/vsce": "^2.23.0",
"effect": "2.3.5",
"effect": "2.3.6",
"glob": "^10.3.10",
"mocha": "^10.3.0",
"prettier": "^3.2.5",
Expand Down
50 changes: 25 additions & 25 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 10 additions & 2 deletions src/Clients.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,10 @@ import {
registerCommand,
} from "./VsCode"
import * as FiberMap from "effect/FiberMap"
import * as Equal from "effect/Equal"
import * as Hash from "effect/Hash"

export interface Client {
export interface Client extends Equal.Equal {
readonly id: number
readonly spans: Queue.Dequeue<Domain.Span>
readonly metrics: Queue.Dequeue<Domain.MetricsSnapshot>
Expand Down Expand Up @@ -105,6 +107,12 @@ const runServer = Effect.gen(function* (_) {
spans,
metrics,
requestMetrics: serverClient.request({ _tag: "MetricsRequest" }),
[Equal.symbol](that: Client) {
return id === that.id
},
[Hash.symbol]() {
return Hash.number(id)
},
}
yield* _(
Effect.acquireRelease(
Expand All @@ -116,7 +124,7 @@ const runServer = Effect.gen(function* (_) {
Effect.acquireRelease(
SubscriptionRef.update(
activeClient,
Option.orElse(() => Option.some(client)),
Option.orElseSome(() => client),
),
() =>
SubscriptionRef.update(
Expand Down
6 changes: 5 additions & 1 deletion src/MetricsProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,16 @@ export const MetricsProviderLive = treeDataProvider<TreeNode>("effect-metrics")(

yield* _(
clients.activeClient.changes,
Stream.changes,
Stream.tap(_ => (Option.isSome(_) ? reset : Effect.unit)),
Stream.runForEach(_ =>
Option.match(_, {
onNone: () => Effect.unit,
onSome: client =>
ScopedRef.set(currentClient, handleClient(client)),
ScopedRef.set(
currentClient,
Effect.interruptible(handleClient(client)),
),
}),
),
Effect.forkScoped,
Expand Down

0 comments on commit bb3a01d

Please sign in to comment.