forked from artheranet/perftool
-
Notifications
You must be signed in to change notification settings - Fork 0
/
generator.go
55 lines (44 loc) · 972 Bytes
/
generator.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
package main
import (
"github.com/artheranet/arthera-node/logger"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/ethclient"
)
type TxMaker func(*ethclient.Client) (*types.Transaction, error)
type TxCallback func(*types.Receipt, error)
type Transaction struct {
Make TxMaker
Callback TxCallback
Dsc string
}
type Generator interface {
Start() (output <-chan *Transaction)
Stop()
SetTPS(tps float64)
}
type genState struct {
ready chan struct{}
notReadyReason string
Session interface{}
logger.Instance
}
func (s *genState) NotReady(reason string) {
s.notReadyReason = reason
s.ready = make(chan struct{})
}
func (s *genState) IsReady(done <-chan struct{}) bool {
if s.ready == nil {
return true
}
s.Log.Debug("waiting", "reason", s.notReadyReason)
select {
case <-done:
return false
case <-s.ready:
s.ready = nil
return true
}
}
func (s *genState) Ready() {
close(s.ready)
}