Skip to content

Commit

Permalink
maybe
Browse files Browse the repository at this point in the history
  • Loading branch information
hazae41 committed Nov 24, 2023
1 parent ac97503 commit df48031
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 6 deletions.
8 changes: 6 additions & 2 deletions src/mods/box/box.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,11 @@ export class BoxMovedError extends Error {
}
}

export class Box<T extends Disposable> implements Disposable {
export interface MaybeDisposable {
[Symbol.dispose]?: () => void
}

export class Box<T extends MaybeDisposable> implements Disposable {

moved = false

Expand All @@ -23,7 +27,7 @@ export class Box<T extends Disposable> implements Disposable {
[Symbol.dispose]() {
if (this.moved)
return
this.inner[Symbol.dispose]()
this.inner[Symbol.dispose]?.()
}

/**
Expand Down
4 changes: 2 additions & 2 deletions src/mods/copy/copy.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
export type BytesOrCopiable<N extends number = number> =
| Uint8Array & { length: N }
| Copiable<Uint8Array & { length: N }>
| Uint8Array & { readonly length: N }
| Copiable<Uint8Array & { readonly length: N }>

/**
* An object whose bytes can be copied
Expand Down
6 changes: 4 additions & 2 deletions src/mods/slot/slot.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
import { MaybeDisposable } from "index.js"

/**
* A disposable whose reference can change
*/
export class Slot<T extends Disposable> implements Disposable {
export class Slot<T extends MaybeDisposable> implements Disposable {

constructor(
public inner: T
) { }

[Symbol.dispose]() {
this.inner[Symbol.dispose]()
this.inner[Symbol.dispose]?.()
}

static new<T extends Disposable>(inner: T) {
Expand Down

0 comments on commit df48031

Please sign in to comment.