{"id":19974550,"url":"https://github.com/twooster/olpo","last_synced_at":"2025-05-04T02:32:51.752Z","repository":{"id":38267527,"uuid":"174602919","full_name":"twooster/olpo","owner":"twooster","description":"A Fully Async TypeScript Resource Pool","archived":false,"fork":false,"pushed_at":"2023-01-06T01:42:36.000Z","size":709,"stargazers_count":6,"open_issues_count":17,"forks_count":1,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-10-13T11:58:27.791Z","etag":null,"topics":["javascript","pool","resource-management","resource-pool","typescript"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/twooster.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-03-08T20:14:31.000Z","updated_at":"2021-06-16T19:22:18.000Z","dependencies_parsed_at":"2023-02-05T01:46:13.432Z","dependency_job_id":null,"html_url":"https://github.com/twooster/olpo","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/twooster%2Folpo","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/twooster%2Folpo/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/twooster%2Folpo/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/twooster%2Folpo/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/twooster","download_url":"https://codeload.github.com/twooster/olpo/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":224379812,"owners_count":17301525,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["javascript","pool","resource-management","resource-pool","typescript"],"created_at":"2024-11-13T03:15:23.694Z","updated_at":"2024-11-13T03:15:24.451Z","avatar_url":"https://github.com/twooster.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"![logo](./OLPO.png)\n\n# OLPO - A TypeScript Resource Pool\n\n[![CircleCI](https://circleci.com/gh/twooster/olpo.svg?style=svg)](https://circleci.com/gh/twooster/olpo)\n[![codecov](https://codecov.io/gh/twooster/olpo/branch/master/graph/badge.svg)](https://codecov.io/gh/twooster/olpo)\n\nOLPO is yet another TypeScript resource pool. It's written to be small (~5.8k\nminified), fast, Promise-native, and written in TypeScript.  It has no\nexternal dependencies and will maintain 100% test coverage.\n\nRequires ES6 support (Node \u003e= 6.4, or a somewhat modern browser). (You may\nalso cross-compile your own ES5 version by modifying `tsconfig.json`).\n\n## Installation\n\n```sh\nnpm install --save olpo\n```\n\n## Documentation\n\n**Documentation is available [here](https://twooster.github.io/olpo)**\n\nDocumentation is updated every version bump. A changelog is available\n[here](https://github.com/twooster/olpo/blob/master/CHANGELOG.md).\n\n## Motivation\n\nThere's a lot of pools out there. A lot of them have a lot of features,\nbut don't have the particular intersection of features I wanted.\n\n* Asynchronous support everywhere\n* Verification of pool items\n* Idle timeouts\n* TypeScript ready, and checked\n\n## Usage\n\nCreate a pool:\n\n```typescript\nimport { Pool } from 'olpo'\nimport { SomeClient } from 'some-client'\n\nconst pool = new Pool({\n  // Required parameters:\n\n  // Synchronous or asynchronous function that creates pool\n  // items.\n  create: async () =\u003e {\n    const cls = new SomeClient()\n    await cls.connect()\n    return cls\n  },\n  // Maximum pool size, must be \u003e `min`\n  max: 10,\n\n  // Optional parameters:\n\n  // Minimum pool size, must be \u003c `max`\n  min: 2,\n  // Which promise library to use (uses builtin ES6 Promise by default)\n  promise: Bluebird,\n  // Default timeout in ms if none is specified as an option during `acquire`\n  acquireTimeout: 5000,\n  // Timeout in ms past which idle pool items will be `dispose`d of, so long as\n  // that disposal doesn't reduce past the minimum pool size\n  idleTimeout: 300000,\n\n  // Called to verify a pool item to determine if it's still valid. Can be\n  // be synchronous or asynchronous. This function should return `true` or\n  // `false`.\n  verify(acq) {\n    const now = new Date();\n    if (acq.uses \u003e 30) {\n      return false;\n    }\n    if (now - acq.createTime \u003e 60000) {\n      return false;\n    }\n    if (now - acq.lastReleaseTime \u003e 20000) {\n      return false;\n    }\n    if (now - acq.lastAcquireTime \u003e 10000) {\n      return false;\n    }\n    return Promise.resolve(asyncCheckIsOk(acq.item))\n  },\n\n  // Called when disposing of a pool item (due to pool shutdown or\n  // if verification fails, or if an item is released to the pool with\n  // the `dispose` flag set to true).\n  // This method can be synchronous or asynchronous. If asynchronous, the\n  // disposal promise will be awaited before space in the pool is released.\n  dispose(acq) {\n    console.log('Disposed: ', acq.item)\n  },\n\n  // Callbacks. These are mainly event callbacks useful for logging -- be sure\n  // not to throw errors from here, as they are not handled within the pooling\n  // code:\n\n  // Called immediately before an item is acquired\n  onAcquire(acq) {\n    console.log('Acquired: ', acq.item)\n  },\n\n  // Called immediately after an item has been released, potentially\n  // immediately before it's disposed, if necessary\n  onRelease(acq) {\n    console.log('Released: ', acq.item)\n  },\n\n  // Called when an acquire fails (mainly for logging)\n  onTimeout({ timeout }) {\n    console.log('Timeout hit: ', timeout)\n  },\n\n  // Called when an asynchronous error occurs -- `type` can be `'create'`,\n  // `'verify'`, or `'dispose'`, indicating errors that occur during those\n  // operations\n  onError(type, err) {\n    console.log('Uncaught error when performing ' + type + ': ' + err)\n  }\n})\n```\n\nAnd then acquire resources:\n\n```typescript\npool.acquire({ timeout: 1000 }).then(poolItem =\u003e {\n  const someClassInstance = poolItem.item\n  someClassInstance.doStuff()\n  // Be sure to release\n  poolItem.release()\n})\n```\n\nOr acquire them this way (the acquired item is automatically released when the\ncallback has completed):\n\n```typescript\npool.acquire(someClassInstance =\u003e {\n  someClassInstance.doStuff()\n}, { timeout: 1000 })\n```\n\nMaybe you want to release a resource but not add it back to the\npool. Easy:\n\n```typescript\npool.acquire({ timeout: 1000 }).then(poolItem =\u003e {\n  const someClassInstance = poolItem.item\n  const wasSuccessful = someClassInstance.doStuff()\n  // If `true` is passed to release, it disposes of the returned\n  // client\n  poolItem.release(!wasSuccessful)\n})\n```\n\n## License\n\nMIT, available [here](https://github.com/twooster/olpo/blob/master/LICENSE).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftwooster%2Folpo","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftwooster%2Folpo","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftwooster%2Folpo/lists"}