MCPcopy Create free account
hub / github.com/cairoeth/preconfirmations / MultipleWorkers

Function MultipleWorkers

preconf-share/simqueue/multiworker.go:12–26  ·  view source on GitHub ↗

MultipleWorkers creates n workers that are rate limited by limit. Use case is to have multiple workers per simulation node. ProcessFunc must be thread safe.

(processFunc ProcessFunc, n int, limit rate.Limit, burst int)

Source from the content-addressed store, hash-verified

10// Use case is to have multiple workers per simulation node.
11// ProcessFunc must be thread safe.
12func MultipleWorkers(processFunc ProcessFunc, n int, limit rate.Limit, burst int) []ProcessFunc {
13 rateLimiter := rate.NewLimiter(limit, burst)
14
15 process := make([]ProcessFunc, n)
16 for i := 0; i < n; i++ {
17 process[i] = func(ctx context.Context, data []byte, info QueueItemInfo) error {
18 err := rateLimiter.Wait(ctx)
19 if err != nil {
20 return err
21 }
22 return processFunc(ctx, data, info)
23 }
24 }
25 return process
26}

Callers 2

StartMethod · 0.92
TestRedisQueueFunction · 0.85

Calls

no outgoing calls

Tested by 1

TestRedisQueueFunction · 0.68