@dxos/context
Advanced tools
Comparing version 0.6.4 to 0.6.5-staging.435ed25
@@ -1,1 +0,1 @@ | ||
{"inputs":{"packages/common/context/src/context-disposed-error.ts":{"bytes":853,"imports":[],"format":"esm"},"packages/common/context/src/context.ts":{"bytes":25119,"imports":[{"path":"@dxos/node-std/util","kind":"import-statement","external":true},{"path":"@dxos/log","kind":"import-statement","external":true},{"path":"@dxos/util","kind":"import-statement","external":true},{"path":"packages/common/context/src/context-disposed-error.ts","kind":"import-statement","original":"./context-disposed-error"}],"format":"esm"},"packages/common/context/src/promise-utils.ts":{"bytes":3096,"imports":[{"path":"packages/common/context/src/context-disposed-error.ts","kind":"import-statement","original":"./context-disposed-error"}],"format":"esm"},"packages/common/context/src/resource.ts":{"bytes":14074,"imports":[{"path":"@dxos/util","kind":"import-statement","external":true},{"path":"packages/common/context/src/context.ts","kind":"import-statement","original":"./context"}],"format":"esm"},"packages/common/context/src/index.ts":{"bytes":809,"imports":[{"path":"packages/common/context/src/context.ts","kind":"import-statement","original":"./context"},{"path":"packages/common/context/src/promise-utils.ts","kind":"import-statement","original":"./promise-utils"},{"path":"packages/common/context/src/context-disposed-error.ts","kind":"import-statement","original":"./context-disposed-error"},{"path":"packages/common/context/src/resource.ts","kind":"import-statement","original":"./resource"}],"format":"esm"}},"outputs":{"packages/common/context/dist/lib/browser/index.mjs.map":{"imports":[],"exports":[],"inputs":{},"bytes":19523},"packages/common/context/dist/lib/browser/index.mjs":{"imports":[{"path":"@dxos/node-std/util","kind":"import-statement","external":true},{"path":"@dxos/log","kind":"import-statement","external":true},{"path":"@dxos/util","kind":"import-statement","external":true},{"path":"@dxos/util","kind":"import-statement","external":true}],"exports":["Context","ContextDisposedError","LifecycleState","Resource","cancelWithContext","openInContext","rejectOnDispose"],"entryPoint":"packages/common/context/src/index.ts","inputs":{"packages/common/context/src/context.ts":{"bytesInOutput":6814},"packages/common/context/src/context-disposed-error.ts":{"bytesInOutput":106},"packages/common/context/src/index.ts":{"bytesInOutput":0},"packages/common/context/src/promise-utils.ts":{"bytesInOutput":410},"packages/common/context/src/resource.ts":{"bytesInOutput":3476}},"bytes":11210}}} | ||
{"inputs":{"packages/common/context/src/context-disposed-error.ts":{"bytes":853,"imports":[],"format":"esm"},"packages/common/context/src/context.ts":{"bytes":28261,"imports":[{"path":"@dxos/node-std/util","kind":"import-statement","external":true},{"path":"@dxos/debug","kind":"import-statement","external":true},{"path":"@dxos/log","kind":"import-statement","external":true},{"path":"@dxos/util","kind":"import-statement","external":true},{"path":"packages/common/context/src/context-disposed-error.ts","kind":"import-statement","original":"./context-disposed-error"}],"format":"esm"},"packages/common/context/src/promise-utils.ts":{"bytes":3096,"imports":[{"path":"packages/common/context/src/context-disposed-error.ts","kind":"import-statement","original":"./context-disposed-error"}],"format":"esm"},"packages/common/context/src/resource.ts":{"bytes":14074,"imports":[{"path":"@dxos/util","kind":"import-statement","external":true},{"path":"packages/common/context/src/context.ts","kind":"import-statement","original":"./context"}],"format":"esm"},"packages/common/context/src/index.ts":{"bytes":809,"imports":[{"path":"packages/common/context/src/context.ts","kind":"import-statement","original":"./context"},{"path":"packages/common/context/src/promise-utils.ts","kind":"import-statement","original":"./promise-utils"},{"path":"packages/common/context/src/context-disposed-error.ts","kind":"import-statement","original":"./context-disposed-error"},{"path":"packages/common/context/src/resource.ts","kind":"import-statement","original":"./resource"}],"format":"esm"}},"outputs":{"packages/common/context/dist/lib/browser/index.mjs.map":{"imports":[],"exports":[],"inputs":{},"bytes":20999},"packages/common/context/dist/lib/browser/index.mjs":{"imports":[{"path":"@dxos/node-std/util","kind":"import-statement","external":true},{"path":"@dxos/debug","kind":"import-statement","external":true},{"path":"@dxos/log","kind":"import-statement","external":true},{"path":"@dxos/util","kind":"import-statement","external":true},{"path":"@dxos/util","kind":"import-statement","external":true}],"exports":["Context","ContextDisposedError","LifecycleState","Resource","cancelWithContext","openInContext","rejectOnDispose"],"entryPoint":"packages/common/context/src/index.ts","inputs":{"packages/common/context/src/context.ts":{"bytesInOutput":7516},"packages/common/context/src/context-disposed-error.ts":{"bytesInOutput":106},"packages/common/context/src/index.ts":{"bytesInOutput":0},"packages/common/context/src/promise-utils.ts":{"bytesInOutput":410},"packages/common/context/src/resource.ts":{"bytesInOutput":3476}},"bytes":11912}}} |
@@ -1,1 +0,1 @@ | ||
{"inputs":{"packages/common/context/src/context-disposed-error.ts":{"bytes":853,"imports":[],"format":"esm"},"packages/common/context/src/context.ts":{"bytes":25119,"imports":[{"path":"node:util","kind":"import-statement","external":true},{"path":"@dxos/log","kind":"import-statement","external":true},{"path":"@dxos/util","kind":"import-statement","external":true},{"path":"packages/common/context/src/context-disposed-error.ts","kind":"import-statement","original":"./context-disposed-error"}],"format":"esm"},"packages/common/context/src/promise-utils.ts":{"bytes":3096,"imports":[{"path":"packages/common/context/src/context-disposed-error.ts","kind":"import-statement","original":"./context-disposed-error"}],"format":"esm"},"packages/common/context/src/resource.ts":{"bytes":14074,"imports":[{"path":"@dxos/util","kind":"import-statement","external":true},{"path":"packages/common/context/src/context.ts","kind":"import-statement","original":"./context"}],"format":"esm"},"packages/common/context/src/index.ts":{"bytes":809,"imports":[{"path":"packages/common/context/src/context.ts","kind":"import-statement","original":"./context"},{"path":"packages/common/context/src/promise-utils.ts","kind":"import-statement","original":"./promise-utils"},{"path":"packages/common/context/src/context-disposed-error.ts","kind":"import-statement","original":"./context-disposed-error"},{"path":"packages/common/context/src/resource.ts","kind":"import-statement","original":"./resource"}],"format":"esm"}},"outputs":{"packages/common/context/dist/lib/node/index.cjs.map":{"imports":[],"exports":[],"inputs":{},"bytes":19523},"packages/common/context/dist/lib/node/index.cjs":{"imports":[{"path":"node:util","kind":"import-statement","external":true},{"path":"@dxos/log","kind":"import-statement","external":true},{"path":"@dxos/util","kind":"import-statement","external":true},{"path":"@dxos/util","kind":"import-statement","external":true}],"exports":["Context","ContextDisposedError","LifecycleState","Resource","cancelWithContext","openInContext","rejectOnDispose"],"entryPoint":"packages/common/context/src/index.ts","inputs":{"packages/common/context/src/context.ts":{"bytesInOutput":6804},"packages/common/context/src/context-disposed-error.ts":{"bytesInOutput":106},"packages/common/context/src/index.ts":{"bytesInOutput":0},"packages/common/context/src/promise-utils.ts":{"bytesInOutput":410},"packages/common/context/src/resource.ts":{"bytesInOutput":3476}},"bytes":11200}}} | ||
{"inputs":{"packages/common/context/src/context-disposed-error.ts":{"bytes":853,"imports":[],"format":"esm"},"packages/common/context/src/context.ts":{"bytes":28261,"imports":[{"path":"node:util","kind":"import-statement","external":true},{"path":"@dxos/debug","kind":"import-statement","external":true},{"path":"@dxos/log","kind":"import-statement","external":true},{"path":"@dxos/util","kind":"import-statement","external":true},{"path":"packages/common/context/src/context-disposed-error.ts","kind":"import-statement","original":"./context-disposed-error"}],"format":"esm"},"packages/common/context/src/promise-utils.ts":{"bytes":3096,"imports":[{"path":"packages/common/context/src/context-disposed-error.ts","kind":"import-statement","original":"./context-disposed-error"}],"format":"esm"},"packages/common/context/src/resource.ts":{"bytes":14074,"imports":[{"path":"@dxos/util","kind":"import-statement","external":true},{"path":"packages/common/context/src/context.ts","kind":"import-statement","original":"./context"}],"format":"esm"},"packages/common/context/src/index.ts":{"bytes":809,"imports":[{"path":"packages/common/context/src/context.ts","kind":"import-statement","original":"./context"},{"path":"packages/common/context/src/promise-utils.ts","kind":"import-statement","original":"./promise-utils"},{"path":"packages/common/context/src/context-disposed-error.ts","kind":"import-statement","original":"./context-disposed-error"},{"path":"packages/common/context/src/resource.ts","kind":"import-statement","original":"./resource"}],"format":"esm"}},"outputs":{"packages/common/context/dist/lib/node/index.cjs.map":{"imports":[],"exports":[],"inputs":{},"bytes":20999},"packages/common/context/dist/lib/node/index.cjs":{"imports":[{"path":"node:util","kind":"import-statement","external":true},{"path":"@dxos/debug","kind":"import-statement","external":true},{"path":"@dxos/log","kind":"import-statement","external":true},{"path":"@dxos/util","kind":"import-statement","external":true},{"path":"@dxos/util","kind":"import-statement","external":true}],"exports":["Context","ContextDisposedError","LifecycleState","Resource","cancelWithContext","openInContext","rejectOnDispose"],"entryPoint":"packages/common/context/src/index.ts","inputs":{"packages/common/context/src/context.ts":{"bytesInOutput":7506},"packages/common/context/src/context-disposed-error.ts":{"bytesInOutput":106},"packages/common/context/src/index.ts":{"bytesInOutput":0},"packages/common/context/src/promise-utils.ts":{"bytesInOutput":410},"packages/common/context/src/resource.ts":{"bytesInOutput":3476}},"bytes":11902}}} |
{ | ||
"name": "@dxos/context", | ||
"version": "0.6.4", | ||
"version": "0.6.5-staging.435ed25", | ||
"description": "Async utils.", | ||
@@ -9,7 +9,15 @@ "homepage": "https://dxos.org", | ||
"author": "DXOS.org", | ||
"main": "dist/lib/node/index.cjs", | ||
"browser": { | ||
"./dist/lib/node/index.cjs": "./dist/lib/browser/index.mjs" | ||
"exports": { | ||
".": { | ||
"browser": "./dist/lib/browser/index.mjs", | ||
"node": { | ||
"default": "./dist/lib/node/index.cjs" | ||
}, | ||
"types": "./dist/types/src/index.d.ts" | ||
} | ||
}, | ||
"types": "dist/types/src/index.d.ts", | ||
"typesVersions": { | ||
"*": {} | ||
}, | ||
"files": [ | ||
@@ -20,5 +28,6 @@ "dist", | ||
"dependencies": { | ||
"@dxos/log": "0.6.4", | ||
"@dxos/util": "0.6.4", | ||
"@dxos/node-std": "0.6.4" | ||
"@dxos/util": "0.6.5-staging.435ed25", | ||
"@dxos/node-std": "0.6.5-staging.435ed25", | ||
"@dxos/debug": "0.6.5-staging.435ed25", | ||
"@dxos/log": "0.6.5-staging.435ed25" | ||
}, | ||
@@ -25,0 +34,0 @@ "publishConfig": { |
@@ -96,2 +96,17 @@ // | ||
}); | ||
test('leak test', async () => { | ||
const ctx = new Context(); | ||
ctx.maxSafeDisposeCallbacks = 1; | ||
ctx.onDispose(() => {}); | ||
const triggerLeak = () => { | ||
ctx.onDispose(() => {}); | ||
}; | ||
triggerLeak(); | ||
triggerLeak(); | ||
}); | ||
}); |
@@ -7,2 +7,3 @@ // | ||
import { StackTrace } from '@dxos/debug'; | ||
import { type CallMetadata, log } from '@dxos/log'; | ||
@@ -42,2 +43,11 @@ import { safeInstanceof } from '@dxos/util'; | ||
type ContextFlags = number; | ||
const CONTEXT_FLAG_IS_DISPOSED: ContextFlags = 1 << 0; | ||
/** | ||
* Whether the dispose callback leak was detected. | ||
*/ | ||
const CONTEXT_FLAG_LEAK_DETECTED: ContextFlags = 1 << 1; | ||
@safeInstanceof('Context') | ||
@@ -56,3 +66,3 @@ export class Context { | ||
#isDisposed = false; | ||
#flags: ContextFlags = 0; | ||
#disposePromise?: Promise<boolean> = undefined; | ||
@@ -69,2 +79,18 @@ | ||
get #isDisposed() { | ||
return !!(this.#flags & CONTEXT_FLAG_IS_DISPOSED); | ||
} | ||
set #isDisposed(value: boolean) { | ||
this.#flags = value ? this.#flags | CONTEXT_FLAG_IS_DISPOSED : this.#flags & ~CONTEXT_FLAG_IS_DISPOSED; | ||
} | ||
get #leakDetected() { | ||
return !!(this.#flags & CONTEXT_FLAG_LEAK_DETECTED); | ||
} | ||
set #leakDetected(value: boolean) { | ||
this.#flags = value ? this.#flags | CONTEXT_FLAG_LEAK_DETECTED : this.#flags & ~CONTEXT_FLAG_LEAK_DETECTED; | ||
} | ||
get disposed() { | ||
@@ -100,5 +126,8 @@ return this.#isDisposed; | ||
this.#disposeCallbacks.push(callback); | ||
if (this.#disposeCallbacks.length > this.maxSafeDisposeCallbacks) { | ||
if (this.#disposeCallbacks.length > this.maxSafeDisposeCallbacks && !this.#leakDetected) { | ||
this.#leakDetected = true; | ||
const callSite = new StackTrace().getStackArray(1)[0].trim(); | ||
log.warn('Context has a large number of dispose callbacks (this might be a memory leak).', { | ||
context: this.#name, | ||
callSite, | ||
count: this.#disposeCallbacks.length, | ||
@@ -105,0 +134,0 @@ }); |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
98112
1487
4
+ Added@dxos/debug@0.6.5-staging.435ed25(transitive)
+ Added@dxos/invariant@0.6.5-staging.435ed25(transitive)
+ Added@dxos/keys@0.6.5-staging.435ed25(transitive)
+ Added@dxos/log@0.6.5-staging.435ed25(transitive)
+ Added@dxos/node-std@0.6.5-staging.435ed25(transitive)
+ Added@dxos/util@0.6.5-staging.435ed25(transitive)
- Removed@dxos/debug@0.6.4(transitive)
- Removed@dxos/invariant@0.6.4(transitive)
- Removed@dxos/keys@0.6.4(transitive)
- Removed@dxos/log@0.6.4(transitive)
- Removed@dxos/node-std@0.6.4(transitive)
- Removed@dxos/util@0.6.4(transitive)