]> zoso.dev Git - libnemo.git/commitdiff
Add function return typings and variable typings.
authorChris Duncan <chris@zoso.dev>
Tue, 3 Dec 2024 20:17:05 +0000 (12:17 -0800)
committerChris Duncan <chris@zoso.dev>
Tue, 3 Dec 2024 20:17:05 +0000 (12:17 -0800)
src/lib/pool.ts

index dad96c6537269299bff1c86a31f8b6a1f3966e15..76daf0fc0163ad29a9b7503e247e36dbd2677dd7 100644 (file)
@@ -21,11 +21,11 @@ export class Pool {
        #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
@@ -51,7 +51,7 @@ export class Pool {
                }
        }
 
-       #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
@@ -59,8 +59,7 @@ export class Pool {
                }
        }
 
-       #report (thread: Thread, result: any[]) {
-               this.#results.push(...result)
+       #report (thread: Thread, result: any[]): void {
                thread.isBusy = false
                if (this.#approach === 'converge') {
                        this.#stop()
@@ -70,7 +69,7 @@ export class Pool {
                }
        }
 
-       #stop () {
+       #stop (): void {
                for (const thread of this.#threads) {
                        const msg = ['stop']
                        const buf = new TextEncoder().encode(JSON.stringify(msg)).buffer