-
Notifications
You must be signed in to change notification settings - Fork 81
/
interface_with_robinpool.go
executable file
·73 lines (60 loc) · 2.63 KB
/
interface_with_robinpool.go
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
// Code generated by gowrap. DO NOT EDIT.
// template: ../templates/robinpool
// gowrap: http://github.com/hexdigest/gowrap
package templatestests
//go:generate gowrap gen -p github.com/hexdigest/gowrap/templates_tests -i TestInterface -t ../templates/robinpool -o interface_with_robinpool.go -l ""
import (
"context"
"errors"
"sync/atomic"
)
// TestInterfaceRoundRobinPool implements TestInterface that uses pool of TestInterface
type TestInterfaceRoundRobinPool struct {
pool []TestInterface
poolSize uint32
counter uint32
}
// NewTestInterfaceRoundRobinPool takes several implementations of the TestInterface and returns an instance of the TestInterface
// that picks one of the given implementations using Round-robin algorithm and delegates method call to it
func NewTestInterfaceRoundRobinPool(pool ...TestInterface) (*TestInterfaceRoundRobinPool, error) {
if len(pool) == 0 {
return nil, errors.New("empty pool")
}
return &TestInterfaceRoundRobinPool{pool: pool, poolSize: uint32(len(pool))}, nil
}
// MustNewTestInterfaceRoundRobinPool takes several implementations of the TestInterface and returns an instance of the TestInterface
// that picks one of the given implementations using Round-robin algorithm and delegates method call to it.
func MustNewTestInterfaceRoundRobinPool(pool ...TestInterface) *TestInterfaceRoundRobinPool {
if len(pool) == 0 {
panic("empty pool")
}
return &TestInterfaceRoundRobinPool{pool: pool, poolSize: uint32(len(pool))}
}
// Channels implements TestInterface
func (_d *TestInterfaceRoundRobinPool) Channels(chA chan bool, chB chan<- bool, chanC <-chan bool) {
_counter := atomic.AddUint32(&_d.counter, 1)
_d.pool[_counter%_d.poolSize].Channels(chA, chB, chanC)
return
}
// ContextNoError implements TestInterface
func (_d *TestInterfaceRoundRobinPool) ContextNoError(ctx context.Context, a1 string, a2 string) {
_counter := atomic.AddUint32(&_d.counter, 1)
_d.pool[_counter%_d.poolSize].ContextNoError(ctx, a1, a2)
return
}
// F implements TestInterface
func (_d *TestInterfaceRoundRobinPool) F(ctx context.Context, a1 string, a2 ...string) (result1 string, result2 string, err error) {
_counter := atomic.AddUint32(&_d.counter, 1)
return _d.pool[_counter%_d.poolSize].F(ctx, a1, a2...)
}
// NoError implements TestInterface
func (_d *TestInterfaceRoundRobinPool) NoError(s1 string) (s2 string) {
_counter := atomic.AddUint32(&_d.counter, 1)
return _d.pool[_counter%_d.poolSize].NoError(s1)
}
// NoParamsOrResults implements TestInterface
func (_d *TestInterfaceRoundRobinPool) NoParamsOrResults() {
_counter := atomic.AddUint32(&_d.counter, 1)
_d.pool[_counter%_d.poolSize].NoParamsOrResults()
return
}