Once in a while you'll find yourself needing some kind of a pool that holds some recyclable resources like – for example – database connections (which can be quite expensive).
A FiFo like (First In First Out) list comes to mind which could take any resources and give them back.
However, Go
provides a much smarter data structure for this purpose: channels
. And such a channel
serves internally as the backbone of this resources pool.
You can use Go
to install this package for you:
go get -u github.com/mwat56/respool
//TODO
No external libraries were used building respool
.
This package is based on the "pool" example in
William Kennedy, Brian Ketelsen, Erik St. Martin:
Go in Action; Shelter Island: Manning, 2015; Chapter 7
Example provided with help from Fatih Arslan and Gabriel Aszalos.
with some modifications and additions from me.
Copyright © 2023 M.Watermann, 10247 Berlin, Germany
All rights reserved
EMail : <support@mwat.de>
This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version.
This software is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
You should have received a copy of the GNU General Public License along with this program. If not, see the GNU General Public License for details.
The original code is published under the MIT Licence.