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

Method runPoolTask

src/master/pool.ts:162–191  ·  view source on GitHub ↗
(worker: WorkerDescriptor<ThreadType>, task: QueuedTask<ThreadType, any>)

Source from the content-addressed store, hash-verified

160 }
161
162 private async runPoolTask(worker: WorkerDescriptor<ThreadType>, task: QueuedTask<ThreadType, any>) {
163 const workerID = this.workers.indexOf(worker) + 1
164
165 this.debug(`Running task #${task.id} on worker #${workerID}...`)
166 this.eventSubject.next({
167 type: PoolEventType.taskStart,
168 taskID: task.id,
169 workerID
170 })
171
172 try {
173 const returnValue = await task.run(await worker.init)
174
175 this.debug(`Task #${task.id} completed successfully`)
176 this.eventSubject.next({
177 type: PoolEventType.taskCompleted,
178 returnValue,
179 taskID: task.id,
180 workerID
181 })
182 } catch (error) {
183 this.debug(`Task #${task.id} failed`)
184 this.eventSubject.next({
185 type: PoolEventType.taskFailed,
186 taskID: task.id,
187 error,
188 workerID
189 })
190 }
191 }
192
193 private async run(worker: WorkerDescriptor<ThreadType>, task: QueuedTask<ThreadType, any>) {
194 const runPromise = (async () => {

Callers 1

runMethod · 0.95

Calls 2

runMethod · 0.80
nextMethod · 0.45

Tested by

no test coverage detected