#approach: 'converge' | 'divide' = 'divide'
#cores: number = Math.max(1, navigator.hardwareConcurrency ?? 1 - 1)
#queue: object[] = []
- #resolve: Function = (value: unknown) => { }
+ #resolve: Function = (value: unknown): void => { }
#results: object[] = []
#threads: Thread[] = []
- get isDone () {
+ get isDone (): boolean {
for (const thread of this.#threads) {
if (thread.isBusy) {
return false
}
}
- #assign (thread: Thread, next: any[]) {
+ #assign (thread: Thread, next: any[]): void {
if (next.length > 0) {
thread.isBusy = true
const buf = new TextEncoder().encode(JSON.stringify(next)).buffer
}
}
- #report (thread: Thread, result: any[]) {
- this.#results.push(...result)
+ #report (thread: Thread, result: any[]): void {
thread.isBusy = false
if (this.#approach === 'converge') {
this.#stop()
}
}
- #stop () {
+ #stop (): void {
for (const thread of this.#threads) {
const msg = ['stop']
const buf = new TextEncoder().encode(JSON.stringify(msg)).buffer