Skip to content

Commit 20a539b

Browse files
committed
feat: dispose sequence
1 parent d90ecf8 commit 20a539b

4 files changed

Lines changed: 655 additions & 15 deletions

File tree

‎container_context.ts‎

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,8 @@ export class ContainerContext extends Container {
66
_disposed?: Promise<void>; // closing promise (promise lock)
77

88
constructor(
9-
readonly importedContainers: Container[],
109
readonly _storage: Map<ServiceIdentifier, unknown>,
11-
readonly disposeHandler?: () => Promise<void>,
10+
readonly disposeHandler: () => Promise<void>,
1211
) {
1312
super();
1413
}
@@ -30,12 +29,7 @@ export class ContainerContext extends Container {
3029

3130
dispose(): Promise<void> {
3231
if (!this._disposed) {
33-
this._disposed = Promise.resolve(this.disposeHandler?.())
34-
.then(() =>
35-
Promise.all(
36-
this.importedContainers.map((m) => m.dispose()),
37-
)
38-
).then(() => {});
32+
this._disposed = Promise.resolve(this.disposeHandler?.());
3933
}
4034
return this._disposed;
4135
}

‎container_state.ts‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import type { Container } from "./container.ts";
2+
3+
export interface ContainerState {
4+
ref: number;
5+
}
6+
7+
const containerStateMap = new WeakMap<Container, ContainerState>();
8+
9+
export function getContainerState(container: Container): ContainerState {
10+
let state = containerStateMap.get(container);
11+
if (!state) {
12+
state = { ref: 0 };
13+
containerStateMap.set(container, state);
14+
}
15+
return state;
16+
}

0 commit comments

Comments
 (0)