Skip to content

Commit

Permalink
clean
Browse files Browse the repository at this point in the history
  • Loading branch information
hazae41 committed Mar 4, 2023
1 parent 097dd26 commit f6a156c
Showing 1 changed file with 12 additions and 9 deletions.
21 changes: 12 additions & 9 deletions src/mods/future/future.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,26 @@
export class Future<T> {

readonly resolve: (value: T) => void
readonly reject: (error: unknown) => void
#resolve?: (value: T) => void
#reject?: (error: unknown) => void

readonly promise: Promise<T>

/**
* Just like a Promise but you can manually resolve or reject it
*/
constructor() {
let resolve: (value: T) => void
let reject: (error: unknown) => void

this.promise = new Promise((subresolve, subreject) => {
resolve = subresolve
reject = subreject
this.#resolve = subresolve
this.#reject = subreject
})
}

this.resolve = resolve!
this.reject = reject!
get resolve() {
return this.#resolve!
}

get reject() {
return this.#reject!
}

}

0 comments on commit f6a156c

Please sign in to comment.