{"id":21972798,"url":"https://github.com/agustinsrg/async-tools","last_synced_at":"2026-01-30T03:05:52.698Z","repository":{"id":57099111,"uuid":"388375541","full_name":"AgustinSRG/async-tools","owner":"AgustinSRG","description":"Collection of tools to work with async funcions in javascript.","archived":false,"fork":false,"pushed_at":"2024-12-05T09:41:15.000Z","size":915,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-10-10T17:13:05.178Z","etag":null,"topics":["async","await","interval","javascript","promise","queue","semaphore"],"latest_commit_sha":null,"homepage":"https://agustinsrg.github.io/async-tools/","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/AgustinSRG.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"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,"zenodo":null}},"created_at":"2021-07-22T07:53:42.000Z","updated_at":"2024-12-05T09:39:52.000Z","dependencies_parsed_at":"2024-06-29T10:49:34.496Z","dependency_job_id":"7ff18d50-1f8a-4e4f-aaa7-00a20b48d423","html_url":"https://github.com/AgustinSRG/async-tools","commit_stats":null,"previous_names":[],"tags_count":6,"template":false,"template_full_name":null,"purl":"pkg:github/AgustinSRG/async-tools","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AgustinSRG%2Fasync-tools","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AgustinSRG%2Fasync-tools/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AgustinSRG%2Fasync-tools/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AgustinSRG%2Fasync-tools/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/AgustinSRG","download_url":"https://codeload.github.com/AgustinSRG/async-tools/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AgustinSRG%2Fasync-tools/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28897662,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-29T21:06:44.224Z","status":"online","status_checked_at":"2026-01-30T02:00:06.810Z","response_time":66,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":["async","await","interval","javascript","promise","queue","semaphore"],"created_at":"2024-11-29T15:21:18.243Z","updated_at":"2026-01-30T03:05:52.628Z","avatar_url":"https://github.com/AgustinSRG.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Async tools\n\n[![npm version](https://badge.fury.io/js/%40asanrom%2Fasync-tools.svg)](https://badge.fury.io/js/%40asanrom%2Fasync-tools)\n\nCollection of tools to work with async functions in javascript.\n\n## Installation\n\nIf you are using a npm managed project use:\n\n```\nnpm install @asanrom/async-tools\n```\n\nIf you are using it in the browser, download the minified file from the [Releases](https://github.com/AgustinSRG/async-tools/tags) section and import it to your html:\n\n```html\n\u003cscript type=\"text/javascript\" src=\"/path/to/async-tools.js\"\u003e\u003c/script\u003e\n```\n\nThe browser library exports all artifacts to the window global: `AsyncTools`\n\n## Async Interval\n\nInterval that waits for the async function to end before running it again. Prevent multiple simultaneous executions.\n\nExample use case: Async periodic task\n\nUsage:\n\n```ts\nimport { AsyncInterval } from \"@asanrom/async-tools\";\n\nconst interval = new AsyncInterval(async function () {\n    await doSomethingAsync();\n}, 1000 /* Milliseconds */);\n\ninterval.on(\"error\", error =\u003e {\n    // If the promise is rejected it will emit\n    // and error event. If you want the interval to continue\n    // when this happens, you have to assign an error handler\n    console.error(error);\n});\n\ninterval.start(); // Start the interval\n\ninterval.stop(); // Stops / Clears the interval\n```\n\n## Async Queue\n\nQueue with an async item handler.\n\n - Items are handled in order (FIFO)\n - If the handler is an async function, it waits for it to finish before dispatching the next item\n\nUsage:\n\n```ts\nimport { AsyncQueue } from \"@asanrom/async-tools\";\n\nconst queue = new AsyncQueue(\n    MAX_SIZE, // Max size of the queue or 0 for unlimited size\n    async function (item) { // Item handler\n        await doSomethingAsync(item)\n    }\n);\n\nqueue.on(\"error\", error =\u003e {\n    // If the promise is rejected it will emit\n    // and error event. If you want the queue to continue\n    // when this happens, you have to assign an error handler\n    console.error(error);\n});\n\nconst items = [1, 2, 3, 4];\nitems.forEach(item =\u003e {\n    // Use push(item) to push items to the queue\n    // They will be dispatched automatically\n    // Push will return false if the item was dropped\n    queue.push(item);\n});\n\n// We can check the size of the queue (number of items in it)\nqueue.getCurrentSize();\n\n// Also we can check if it's full\nqueue.isFull();\n\n// If we want to release the resources of the queue\n// we can call destroy()\n// It returns a promise that waits if there is an item\n// in the mid of being handled\nawait queue.destroy();\n```\n\n## Async Semaphore\n\nSemaphore to create critical sections on async functions.\n\nUsage:\n\n```ts\nimport { AsyncSemaphore } from \"@asanrom/async-tools\";\n\n\nconst sem = new AsyncSemaphore(); // Without params, initial instances is 1 (Mutex)\nconst sem3Instances = new AsyncSemaphore(3); // 3 initial instances\n\n// Acquire instances, if it can't acquire\n// the promise will resolve when the instances are available\n// it will reject if the semaphore is destroyed\nawait sem.acquire();\n\n// Release instances and resolve the promises\nsem.release();\n\n// Rejects all promises waiting to acquire the semaphore\n// After destroyed, it cannot be used anymore\nsem.destroy();\n```\n\n## Async Provider\n\nProvides values asynchronously, allowing a function to await the value while other function eventually provides the value.\n\nIt also provides a timeout option to set a max time to wait for the value.\n\nUsage:\n\n```ts\nimport { AsyncProvider } from \"@asanrom/async-tools\";\n\n// Create a provider\nconst provider = new AsyncProvider(2000 /* Timeout in milliseconds as the constructor argument */);\n\nserver.on(\"message\", msg =\u003e {\n    // You can asynchronously provide a value.\n    // For example, when an event is received\n    provider.provideValue(msg);\n});\n\n\nserver.on(\"error\", err =\u003e {\n    // You can also asynchronously provide an error\n    provider.provideError(err);\n});\n\ntry {\n    // You can await for the value\n    // The promise will be resolved if 'provideValue' is called on time\n    // The promise will reject if the timeout is reached or 'provideError' is called\n    const value = await provider.getValue();\n\n    console.log(\"Value: \" + value);\n} catch (ex) {\n    if (AsyncProvider.isTimeoutError(ex)) { // Check if the error is a timeout error\n        // Timeout error\n        console.error(\"The value was not provided in time!\");\n    } else {\n        // Provided error\n        console.error(ex);\n    }\n}\n```\n\n## Documentation\n\n - [Library documentation (Auto-generated)](https://agustinsrg.github.io/async-tools/)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fagustinsrg%2Fasync-tools","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fagustinsrg%2Fasync-tools","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fagustinsrg%2Fasync-tools/lists"}