From 4492811052d9461bcce5eb59891ff2b5a9a365ab Mon Sep 17 00:00:00 2001 From: Yaroslav Klymko Date: Mon, 18 Sep 2023 12:51:47 +0200 Subject: [PATCH] add example to README.md --- README.md | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/README.md b/README.md index 649e956..8830f72 100644 --- a/README.md +++ b/README.md @@ -14,6 +14,31 @@ Pool of cats-effect resources * shuts down gracefully after completing accumulated tasks * tolerates resource failures +## Example + +```scala +import com.evolution.resourcepool.ResourcePool.implicits._ + +trait Connection { + def query(any: Any): IO[Any] +} + +def connection: Resource[IO, Connection] = ??? + +connection + .toResourcePool( // you can convert any resource into the pool of resources + maxSize = 10, // it will create up to `maxSize` connections + expireAfter = 1.minute) // pool will release connection if it is not used for 1 minute + .use { connectionPool => + connectionPool + .resource // this will get first available connection and there after release it when done + .use { connection => + connection.query() // here you have access to the connection + } + } + +``` + ## Setup ```scala