MCPcopy Index your code
hub / github.com/andywer/threads.js / constructor

Method constructor

src/master/pool.ts:128–155  ·  view source on GitHub ↗
(
    spawnWorker: () => Promise<ThreadType>,
    optionsOrSize?: number | PoolOptions
  )

Source from the content-addressed store, hash-verified

126 private taskQueue: Array<QueuedTask<ThreadType, any>> = []
127
128 constructor(
129 spawnWorker: () => Promise<ThreadType>,
130 optionsOrSize?: number | PoolOptions
131 ) {
132 const options: PoolOptions = typeof optionsOrSize === "number"
133 ? { size: optionsOrSize }
134 : optionsOrSize || {}
135
136 const { size = defaultPoolSize } = options
137
138 this.debug = DebugLogger(`threads:pool:${slugify(options.name || String(nextPoolID++))}`)
139 this.options = options
140 this.workers = spawnWorkers(spawnWorker, size)
141
142 this.eventObservable = multicast(Observable.from(this.eventSubject))
143
144 Promise.all(this.workers.map(worker => worker.init)).then(
145 () => this.eventSubject.next({
146 type: PoolEventType.initialized,
147 size: this.workers.length
148 }),
149 error => {
150 this.debug("Error while initializing pool worker:", error)
151 this.eventSubject.error(error)
152 this.initErrors.push(error)
153 }
154 )
155 }
156
157 private findIdlingWorker(): WorkerDescriptor<ThreadType> | undefined {
158 const { concurrency = 1 } = this.options

Callers

nothing calls this directly

Calls 6

slugifyFunction · 0.85
spawnWorkersFunction · 0.85
fromMethod · 0.80
thenMethod · 0.80
nextMethod · 0.45
errorMethod · 0.45

Tested by

no test coverage detected