mirror of
https://github.com/muun/recovery.git
synced 2025-11-13 07:11:45 -05:00
Update project structure and build process
This commit is contained in:
28
recovery_tool/electrum/pool.go
Normal file
28
recovery_tool/electrum/pool.go
Normal file
@@ -0,0 +1,28 @@
|
||||
package electrum
|
||||
|
||||
// Pool provides a shared pool of Clients that callers can acquire and release, limiting
|
||||
// the amount of concurrent Clients in active use.
|
||||
type Pool struct {
|
||||
nextClient chan *Client
|
||||
}
|
||||
|
||||
// NewPool creates an initialized Pool with a `size` number of clients.
|
||||
func NewPool(size int, requireTls bool) *Pool {
|
||||
nextClient := make(chan *Client, size)
|
||||
|
||||
for i := 0; i < size; i++ {
|
||||
nextClient <- NewClient(requireTls)
|
||||
}
|
||||
|
||||
return &Pool{nextClient}
|
||||
}
|
||||
|
||||
// Acquire obtains an unused Client, blocking until one is released.
|
||||
func (p *Pool) Acquire() <-chan *Client {
|
||||
return p.nextClient
|
||||
}
|
||||
|
||||
// Release returns a Client to the pool, unblocking the next caller trying to `Acquire()`.
|
||||
func (p *Pool) Release(client *Client) {
|
||||
p.nextClient <- client
|
||||
}
|
||||
Reference in New Issue
Block a user