{"id":24512405,"url":"https://github.com/ido-pluto/class-pull","last_synced_at":"2025-03-15T10:10:56.208Z","repository":{"id":188688871,"uuid":"679237003","full_name":"ido-pluto/class-pull","owner":"ido-pluto","description":"Limited uses simultaneously execation","archived":false,"fork":false,"pushed_at":"2024-03-10T11:50:28.000Z","size":78,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-02-22T10:17:30.311Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"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/ido-pluto.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"github":"ido-pluto"}},"created_at":"2023-08-16T11:54:04.000Z","updated_at":"2023-08-16T11:56:43.000Z","dependencies_parsed_at":null,"dependency_job_id":"35482cb5-5038-45c0-bc32-25549852d6af","html_url":"https://github.com/ido-pluto/class-pull","commit_stats":null,"previous_names":["ido-pluto/class-pull"],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ido-pluto%2Fclass-pull","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ido-pluto%2Fclass-pull/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ido-pluto%2Fclass-pull/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ido-pluto%2Fclass-pull/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ido-pluto","download_url":"https://codeload.github.com/ido-pluto/class-pull/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243713415,"owners_count":20335567,"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":[],"created_at":"2025-01-22T00:46:25.951Z","updated_at":"2025-03-15T10:10:56.190Z","avatar_url":"https://github.com/ido-pluto.png","language":"TypeScript","funding_links":["https://github.com/sponsors/ido-pluto"],"categories":[],"sub_categories":[],"readme":"# Class Pull\n\n\u003cdiv align=\"center\"\u003e\n\n[![npm version](https://badge.fury.io/js/class-pull.svg)](https://badge.fury.io/js/catai)\n[![npm downloads](https://img.shields.io/npm/dt/class-pull.svg)](https://www.npmjs.com/package/catai)\n[![GitHub license](https://img.shields.io/github/license/ido-pluto/class-pull)](./LICENSE)\n[![semantic-release: node](https://img.shields.io/badge/semantic--release-node-5dae47?logo=semantic-release)](https://github.com/semantic-release/semantic-release)\n\n\u003c/div\u003e\n\nThis package enables you to manage a class pull.\n\nWith this package, you can:\n- Make sure only limited uses of that class can happen simultaneously\n- Do heavy tasks that require a state\n- Manage pull \u0026 get statistics\n\n### Use example\n\n```javascript\nimport {ClassPull} from 'class-pull';\n\nfunction createState() {\n    return {\n        counter: 0,\n        sleep(ms = 1000) {\n            return new Promise(resolve =\u003e setTimeout(resolve, ms));\n        }\n    };\n}\n\nconst pull = new ClassPull(createState, {limit: 2});\n\nasync function countRef(instance: ReturnType\u003ctypeof createState\u003e) {\n    await instance.sleep(1000);\n    console.log('counter', ++instance.counter);\n}\n\nfunction main() {\n    pull.run(countRef, 5);\n} main();\n\n\n/**\n * Output:\n * counter 1\n * counter 1\n * counter 2\n * counter 2\n * counter 3\n */\n```\n\n### API\n```typescript\nclass ClassPull\u003cState\u003e {\n    new (createInstance: () =\u003e State | Promise\u003cState\u003e, options: ClassPullOptions);\n    run\u003cResponse\u003e(callback: (instance: State) =\u003e Promise\u003cReturns\u003e | Returns, count = 1): Promise\u003cResponse[]\u003e\n\n    lockInstance(): Promise\u003clockInstanceItem\u003e;\n    loadingCount: number;\n    freeCount: number;\n}\n\ntype ClassPullOptions= {\n    limit?: number;\n    createOnInit?: number;\n}\n\ntype lockInstanceItem = {\n    instance: T;\n    unlock: () =\u003e void;\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fido-pluto%2Fclass-pull","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fido-pluto%2Fclass-pull","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fido-pluto%2Fclass-pull/lists"}