blob: 44c899c4e2affdc06ea8d828ecb6462614ce43e3 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
|
// SPDX-FileCopyrightText: Copyright The Miniflux Authors. All rights reserved.
// SPDX-License-Identifier: Apache-2.0
package worker // import "miniflux.app/v2/internal/worker"
import (
"miniflux.app/v2/internal/model"
"miniflux.app/v2/internal/storage"
)
// Pool handles a pool of workers.
type Pool struct {
queue chan model.Job
}
// Push send a list of jobs to the queue.
func (p *Pool) Push(jobs model.JobList) {
for _, job := range jobs {
p.queue <- job
}
}
// NewPool creates a pool of background workers.
func NewPool(store *storage.Storage, nbWorkers int) *Pool {
workerPool := &Pool{
queue: make(chan model.Job),
}
for i := range nbWorkers {
worker := &Worker{id: i, store: store}
go worker.Run(workerPool.queue)
}
return workerPool
}
|