{"id":29022041,"url":"https://github.com/jsweb/asyncs","last_synced_at":"2025-06-26T02:37:38.777Z","repository":{"id":33095742,"uuid":"147448313","full_name":"jsweb/asyncs","owner":"jsweb","description":"Simple JS module for Promise and Fetch APIs, with some useful abstraction","archived":false,"fork":false,"pushed_at":"2022-12-30T17:51:54.000Z","size":1283,"stargazers_count":0,"open_issues_count":7,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-02-23T09:38:36.757Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","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/jsweb.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}},"created_at":"2018-09-05T02:29:27.000Z","updated_at":"2021-06-18T20:13:44.000Z","dependencies_parsed_at":"2023-01-14T23:20:13.150Z","dependency_job_id":null,"html_url":"https://github.com/jsweb/asyncs","commit_stats":null,"previous_names":[],"tags_count":45,"template":false,"template_full_name":null,"purl":"pkg:github/jsweb/asyncs","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jsweb%2Fasyncs","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jsweb%2Fasyncs/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jsweb%2Fasyncs/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jsweb%2Fasyncs/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jsweb","download_url":"https://codeload.github.com/jsweb/asyncs/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jsweb%2Fasyncs/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":261988005,"owners_count":23240949,"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-06-26T02:37:35.859Z","updated_at":"2025-06-26T02:37:38.740Z","avatar_url":"https://github.com/jsweb.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# @jsweb/asyncs\n\nSimple JS module for Promise and Fetch APIs, with some useful abstraction.\n\n![npm-package](https://img.shields.io/badge/npm-package-blue.svg?style=for-the-badge)\n![es6-module](https://img.shields.io/badge/es6-module-blue.svg?style=for-the-badge)\n![tests-mocha](https://img.shields.io/badge/tests-mocha-blue.svg?style=for-the-badge)\n\nSee tests at [https://asyncs.jsweb.app](https://asyncs.jsweb.app)\n\n## New in v4.0.0\n\nNow, its a full ES module, there is no UMD or CommonJS version.\n\nIn modern JS development ES modules are the pattern, already supported in newer versions of Node.js and modern borwsers natively.\n\nBackward compatibility is not a concern here. If you use a module bundler (like Webpack or Rollup) to transpile your code, the result will be compatible according to your setup.\n\n***\n\n## Methods\n  \n\u003ca name=\"exec\"\u003e\u003c/a\u003e\n\n## exec(fn, ...args) ⇒ \u003ccode\u003ePromise\u003c/code\u003e\nExcute any function asyncronously with any number of arguments.\n\n**Returns**: \u003ccode\u003ePromise\u003c/code\u003e - Promise  \n\n| Param | Type |\n| --- | --- |\n| fn | \u003ccode\u003efunction\u003c/code\u003e | \n| ...args | \u003ccode\u003earguments\u003c/code\u003e | \n\n\u003ca name=\"asap\"\u003e\u003c/a\u003e\n\n## asap(fn, ...args) ⇒ \u003ccode\u003e\\*\u003c/code\u003e\nExecute any function asyncronously As Soon As Possible with any number of arguments.\nThis method tries to use setImmediate (if available) or emulate it.\n\n| Param | Type |\n| --- | --- |\n| fn | \u003ccode\u003efunction\u003c/code\u003e | \n| ...args | \u003ccode\u003earguments\u003c/code\u003e | \n\n\u003ca name=\"task\"\u003e\u003c/a\u003e\n\n## task(input, ...args) ⇒ \u003ccode\u003ePromise\u003c/code\u003e\nTurn any input in a Promise to use it on asyncronous threads\n\n**Returns**: \u003ccode\u003ePromise\u003c/code\u003e - Promise  \n\n| Param | Type |\n| --- | --- |\n| input | \u003ccode\u003e\\*\u003c/code\u003e | \n| ...args | \u003ccode\u003earguments\u003c/code\u003e | \n\n\u003ca name=\"execAll\"\u003e\u003c/a\u003e\n\n## execAll(...args) ⇒ \u003ccode\u003ePromise\u003c/code\u003e\nTurn any number of arguments into asyncronous group to resolve only if all threads resolve.\n\n**Returns**: \u003ccode\u003ePromise\u003c/code\u003e - Promise  \n\n| Param | Type |\n| --- | --- |\n| ...args | \u003ccode\u003earguments\u003c/code\u003e | \n\n\u003ca name=\"execRace\"\u003e\u003c/a\u003e\n\n## execRace(...args) ⇒ \u003ccode\u003ePromise\u003c/code\u003e\nTurn any number of arguments into asyncronous race to resolve or reject with the fastest thread.\n\n**Returns**: \u003ccode\u003ePromise\u003c/code\u003e - Promise  \n\n| Param | Type |\n| --- | --- |\n| ...args | \u003ccode\u003earguments\u003c/code\u003e | \n\n\u003ca name=\"request\"\u003e\u003c/a\u003e\n\n## request(url, cfg) ⇒ \u003ccode\u003ePromise\u003c/code\u003e\nExecute asyncronous HTTP requests with configurable options.\n\nThis method uses Fetch API with some useful abstractions.\n\nTo send parameters on request, just add a `body` in `cfg` containing the object for any HTTP method request.\n\nGET requests (default), will serialize parameters into a query string.\n\nOther methods will convert parameters into FormData object if necessary.\n\nSo you can also send HTML Form or FormData object for non GET requests.\n\nIt is also possible to send JSON content. Just set `content-type` to `application/json` at `cfg.headers`.\n\nThen your `cfg.body` literal object will be serialized using `JSON.stringify`.\n\nThe promise returned also checks HTTP response. Any status \u003e= 300 will cause a `Promise.reject`.\n\n**Returns**: \u003ccode\u003ePromise\u003c/code\u003e - Promise  \n\n| Param | Type |\n| --- | --- |\n| url | \u003ccode\u003eString\u003c/code\u003e | \n| cfg | \u003ccode\u003eRequestInit\u003c/code\u003e | \n\n\u003ca name=\"requestAll\"\u003e\u003c/a\u003e\n\n## requestAll(urls, cfg, resp) ⇒ \u003ccode\u003ePromise\u003c/code\u003e\nUse `execAll` to make a `request` for each `urls` using the same `cfg` and `resp` type for all.\n\nThe result Promise resolves only if all requests resolve.\n\nIf any request fails, it will cause an entire `Promise.reject`.\n\nPossible response types are: response (default), json, text, blob, boolean, number, xml and html.\n\n**Returns**: \u003ccode\u003ePromise\u003c/code\u003e - Promise  \n\n| Param | Type | Default |\n| --- | --- | --- |\n| urls | \u003ccode\u003eArray.\u0026lt;String\u0026gt;\u003c/code\u003e |  | \n| cfg | \u003ccode\u003eRequestInit\u003c/code\u003e |  | \n| resp | \u003ccode\u003eString\u003c/code\u003e | \u003ccode\u003eresponse\u003c/code\u003e | \n\n\u003ca name=\"requestRace\"\u003e\u003c/a\u003e\n\n## requestRace(urls, cfg, resp) ⇒ \u003ccode\u003ePromise\u003c/code\u003e\nUse `execRace` to make a `request` race with all `urls` using the same `cfg` and `resp` type for all.\n\nThe result Promise resolves or rejects with the fastest request.\n\nPossible response types are: response (default), json, text, blob, boolean, number, xml and html.\n\n**Returns**: \u003ccode\u003ePromise\u003c/code\u003e - Promise  \n\n| Param | Type | Default |\n| --- | --- | --- |\n| urls | \u003ccode\u003eArray.\u0026lt;String\u0026gt;\u003c/code\u003e |  | \n| cfg | \u003ccode\u003eRequestInit\u003c/code\u003e |  | \n| resp | \u003ccode\u003eString\u003c/code\u003e | \u003ccode\u003eresponse\u003c/code\u003e | \n\n\u003ca name=\"requestJSON\"\u003e\u003c/a\u003e\n\n## requestJSON(url, cfg) ⇒ \u003ccode\u003ePromise\u003c/code\u003e\nExecute a `request` expecting for a valid JSON response.\n\nHTTP errors or invalid JSON response will cause a `Promise.reject`.\n\n**Returns**: \u003ccode\u003ePromise\u003c/code\u003e - Promise  \n\n| Param | Type |\n| --- | --- |\n| url | \u003ccode\u003eString\u003c/code\u003e | \n| cfg | \u003ccode\u003eRequestInit\u003c/code\u003e | \n\n\u003ca name=\"requestText\"\u003e\u003c/a\u003e\n\n## requestText(url, cfg) ⇒ \u003ccode\u003ePromise\u003c/code\u003e\nExecute a `request` expecting for any response and get it as text.\n\nHTTP errors will cause a `Promise.reject`.\n\n**Returns**: \u003ccode\u003ePromise\u003c/code\u003e - Promise  \n\n| Param | Type |\n| --- | --- |\n| url | \u003ccode\u003eString\u003c/code\u003e | \n| cfg | \u003ccode\u003eRequestInit\u003c/code\u003e | \n\n\u003ca name=\"requestBlob\"\u003e\u003c/a\u003e\n\n## requestBlob(url, cfg) ⇒ \u003ccode\u003ePromise\u003c/code\u003e\nExecute a `request` expecting for a valid Blob response.\n\nHTTP errors or not readable Blob response will cause a `Promise.reject`.\n\n**Returns**: \u003ccode\u003ePromise\u003c/code\u003e - Promise  \n\n| Param | Type |\n| --- | --- |\n| url | \u003ccode\u003eString\u003c/code\u003e | \n| cfg | \u003ccode\u003eRequestInit\u003c/code\u003e | \n\n\u003ca name=\"requestBoolean\"\u003e\u003c/a\u003e\n\n## requestBoolean(url, cfg) ⇒ \u003ccode\u003ePromise\u003c/code\u003e\nExecute a `request` expecting for any response and get it as boolean.\n\nHTTP errors will cause a `Promise.reject`.\n\n**Returns**: \u003ccode\u003ePromise\u003c/code\u003e - Promise  \n\n| Param | Type |\n| --- | --- |\n| url | \u003ccode\u003eString\u003c/code\u003e | \n| cfg | \u003ccode\u003eRequestInit\u003c/code\u003e | \n\n\u003ca name=\"requestNumber\"\u003e\u003c/a\u003e\n\n## requestNumber(url, cfg) ⇒ \u003ccode\u003ePromise\u003c/code\u003e\nExecute a `request` expecting for a valid Number response.\n\nThe response can be number, string or any value that can be parsed as Number.\n\nInvalid values will resolve as `NaN` (not a number).\n\nHTTP errors will cause a `Promise.reject`.\n\n**Returns**: \u003ccode\u003ePromise\u003c/code\u003e - Promise  \n\n| Param | Type |\n| --- | --- |\n| url | \u003ccode\u003eString\u003c/code\u003e | \n| cfg | \u003ccode\u003eRequestInit\u003c/code\u003e | \n\n\u003ca name=\"requestXML\"\u003e\u003c/a\u003e\n\n## requestXML(url, cfg) ⇒ \u003ccode\u003ePromise\u003c/code\u003e\nExecute a `request` expecting for a valid XML document response.\n\nHTTP errors response will cause a `Promise.reject`.\n\n**Returns**: \u003ccode\u003ePromise\u003c/code\u003e - Promise  \n\n| Param | Type |\n| --- | --- |\n| url | \u003ccode\u003eString\u003c/code\u003e | \n| cfg | \u003ccode\u003eRequestInit\u003c/code\u003e | \n\n\u003ca name=\"requestHTML\"\u003e\u003c/a\u003e\n\n## requestHTML(url, cfg) ⇒ \u003ccode\u003ePromise\u003c/code\u003e\nExecute a `request` expecting for any response and get it as HTML.\n\nHTTP errors response will cause a `Promise.reject`.\n\n**Returns**: \u003ccode\u003ePromise\u003c/code\u003e - Promise  \n\n| Param | Type |\n| --- | --- |\n| url | \u003ccode\u003eString\u003c/code\u003e | \n| cfg | \u003ccode\u003eRequestInit\u003c/code\u003e | \n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjsweb%2Fasyncs","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjsweb%2Fasyncs","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjsweb%2Fasyncs/lists"}