From bb3a01dd5e90d98a66eaaa001525fa5673f7f3bb Mon Sep 17 00:00:00 2001 From: Tim Date: Thu, 15 Feb 2024 14:51:00 +1300 Subject: [PATCH] ensure metrics is interruptible --- package.json | 4 ++-- pnpm-lock.yaml | 50 +++++++++++++++++++++--------------------- src/Clients.ts | 12 ++++++++-- src/MetricsProvider.ts | 6 ++++- 4 files changed, 42 insertions(+), 30 deletions(-) diff --git a/package.json b/package.json index c64763b..4bd75d2 100644 --- a/package.json +++ b/package.json @@ -135,7 +135,7 @@ "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", @@ -143,7 +143,7 @@ "@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", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index bdc2052..7abcab8 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -12,8 +12,8 @@ devDependencies: specifier: ^2.27.1 version: 2.27.1 '@effect/experimental': - specifier: ^0.9.10 - version: 0.9.10(@effect/platform@0.45.1)(@effect/schema@0.62.6)(effect@2.3.5)(ws@8.16.0) + specifier: ^0.9.11 + version: 0.9.11(@effect/platform@0.45.2)(@effect/schema@0.62.7)(effect@2.3.6)(ws@8.16.0) '@effect/language-service': specifier: ^0.1.0 version: 0.1.0 @@ -36,8 +36,8 @@ devDependencies: specifier: ^2.23.0 version: 2.23.0 effect: - specifier: 2.3.5 - version: 2.3.5 + specifier: 2.3.6 + version: 2.3.6 glob: specifier: ^10.3.10 version: 10.3.10 @@ -293,13 +293,13 @@ packages: prettier: 2.8.8 dev: true - /@effect/experimental@0.9.10(@effect/platform@0.45.1)(@effect/schema@0.62.6)(effect@2.3.5)(ws@8.16.0): - resolution: {integrity: sha512-3GzIx5mHwACe4/r6ObIfzbChe1R0vpl6yb7Tmu8iPp87KoNIOeTbdGukxHhu+XmigwJ6smcxo/1Hnm6OCECNEg==} + /@effect/experimental@0.9.11(@effect/platform@0.45.2)(@effect/schema@0.62.7)(effect@2.3.6)(ws@8.16.0): + resolution: {integrity: sha512-k9ivvF8uGB5VFTaxbJOf7qX5Fbf0rChNFOsa33CE3WJAVFUG8lBvkDPMrmfvWLMwOsDQxOJuo2ooi7wo/Q0jmA==} peerDependencies: - '@effect/platform': ^0.45.1 - '@effect/platform-node': ^0.44.1 - '@effect/schema': ^0.62.6 - effect: ^2.3.5 + '@effect/platform': ^0.45.2 + '@effect/platform-node': ^0.44.2 + '@effect/schema': ^0.62.7 + effect: ^2.3.6 lmdb: ^2.9.2 ws: ^8.14 peerDependenciesMeta: @@ -310,9 +310,9 @@ packages: ws: optional: true dependencies: - '@effect/platform': 0.45.1(@effect/schema@0.62.6)(effect@2.3.5) - '@effect/schema': 0.62.6(effect@2.3.5)(fast-check@3.15.1) - effect: 2.3.5 + '@effect/platform': 0.45.2(@effect/schema@0.62.7)(effect@2.3.6) + '@effect/schema': 0.62.7(effect@2.3.6)(fast-check@3.15.1) + effect: 2.3.6 isomorphic-ws: 5.0.0(ws@8.16.0) msgpackr: 1.10.1 ws: 8.16.0 @@ -322,26 +322,26 @@ packages: resolution: {integrity: sha512-BnlM8LlaqCAYgdRfxlbR7gXGh/FD1scL1fPgNVJEPoOM08od1jtJz+iKhwfaud8TPnnhZR+TED2h5ynjanLeCQ==} dev: true - /@effect/platform@0.45.1(@effect/schema@0.62.6)(effect@2.3.5): - resolution: {integrity: sha512-9nhcNSCM3NWHN8+oKhJ/4XkeHa24pwEwUswpZMguoldIqpMe0CkeWSoK9Zs2wQKUmjbznLZ+emPpnVh4iRSKQg==} + /@effect/platform@0.45.2(@effect/schema@0.62.7)(effect@2.3.6): + resolution: {integrity: sha512-4ZN66gLcuWEWXqWxQcQ+RB7YdlXTtsPDlrjLIAR4p/PFnOYR9TAYvkdGRPd6QkKWOfljN0yQXBVBvIVDXV03TQ==} peerDependencies: - '@effect/schema': ^0.62.6 - effect: ^2.3.5 + '@effect/schema': ^0.62.7 + effect: ^2.3.6 dependencies: - '@effect/schema': 0.62.6(effect@2.3.5)(fast-check@3.15.1) - effect: 2.3.5 + '@effect/schema': 0.62.7(effect@2.3.6)(fast-check@3.15.1) + effect: 2.3.6 find-my-way-ts: 0.1.1 multipasta: 0.1.21 path-browserify: 1.0.1 dev: true - /@effect/schema@0.62.6(effect@2.3.5)(fast-check@3.15.1): - resolution: {integrity: sha512-Y/vkQ63EXcQUiJM01lbZ5lb7wCEK8gTcM5wZ1L20TvqFuAXHLp0cs66L3Sk3eIbiX0mv4aYxBWSKhwvhWAhc6g==} + /@effect/schema@0.62.7(effect@2.3.6)(fast-check@3.15.1): + resolution: {integrity: sha512-AGrnQDC0hw5VknesZm4zGjY7EkgKwp+5kzMcFlna96MFLaGOGinZiZeldGep7ByNWsa4Bbz9BfEQcr/knqJpjw==} peerDependencies: - effect: ^2.3.5 + effect: ^2.3.6 fast-check: ^3.13.2 dependencies: - effect: 2.3.5 + effect: 2.3.6 fast-check: 3.15.1 dev: true @@ -1468,8 +1468,8 @@ packages: resolution: {integrity: sha512-I88TYZWc9XiYHRQ4/3c5rjjfgkjhLyW2luGIheGERbNQ6OY7yTybanSpDXZa8y7VUP9YmDcYa+eyq4ca7iLqWA==} dev: true - /effect@2.3.5: - resolution: {integrity: sha512-qarp/WBRty4VM//ZEKDY8Bu3Tolr1afEIwFVZtU3eMOtBZpRIQkLVQMTOjUTt3qeJAAIHfYfEk7GiKg6ABCWlg==} + /effect@2.3.6: + resolution: {integrity: sha512-R7Sqjc/6Wg+hZbtotklWunLUe5hoEG/a8SP/4BGydNCbR2DZuc15ZApoZA1gVMcT/PDMN3WHEiVlqLkt+TtdBA==} dev: true /emoji-regex@8.0.0: diff --git a/src/Clients.ts b/src/Clients.ts index caf7820..43d0c41 100644 --- a/src/Clients.ts +++ b/src/Clients.ts @@ -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 readonly metrics: Queue.Dequeue @@ -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( @@ -116,7 +124,7 @@ const runServer = Effect.gen(function* (_) { Effect.acquireRelease( SubscriptionRef.update( activeClient, - Option.orElse(() => Option.some(client)), + Option.orElseSome(() => client), ), () => SubscriptionRef.update( diff --git a/src/MetricsProvider.ts b/src/MetricsProvider.ts index 04394fc..21b48f2 100644 --- a/src/MetricsProvider.ts +++ b/src/MetricsProvider.ts @@ -67,12 +67,16 @@ export const MetricsProviderLive = treeDataProvider("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,