{"id":18367657,"url":"https://github.com/jwplayer/overwait","last_synced_at":"2025-06-20T22:40:40.808Z","repository":{"id":198576119,"uuid":"698721115","full_name":"jwplayer/overwait","owner":"jwplayer","description":"A lightweight library to supercharge the await operator!","archived":false,"fork":false,"pushed_at":"2023-10-06T06:10:27.000Z","size":89,"stargazers_count":3,"open_issues_count":0,"forks_count":1,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-03-22T03:51:12.939Z","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":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/jwplayer.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2023-09-30T18:55:40.000Z","updated_at":"2023-11-07T14:55:29.000Z","dependencies_parsed_at":null,"dependency_job_id":"3f108d4a-c76e-4732-a65f-c4f034cda191","html_url":"https://github.com/jwplayer/overwait","commit_stats":null,"previous_names":["jwplayer/overwait"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jwplayer%2Foverwait","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jwplayer%2Foverwait/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jwplayer%2Foverwait/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jwplayer%2Foverwait/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jwplayer","download_url":"https://codeload.github.com/jwplayer/overwait/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247513054,"owners_count":20950981,"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":"2024-11-05T23:22:50.054Z","updated_at":"2025-04-06T16:32:47.894Z","avatar_url":"https://github.com/jwplayer.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Overwait\nA lightweight library to supercharge the await operator!\n\n## Description\nOverwait takes your objects (and functions) and wraps them in a `Proxy` that automatically distributes the `await` operator down every step during property lookups, function return values, etc.\n\n### What does that mean?\nIn practice, overwait transforms `await a.b.c` into `await (await (await a).b).c`.\n\n\n## Usage\n`overwait` is a single function. Simply pass it an object or a function and it'll return a `Proxy` that wraps the original object and intercepts property accesses. For example:\n\n```js\nimport overwait from 'overwait';\n\n// Wrap the fetch function to make it less tedious\nconst fetchy = overwait(fetch);\n```\n\nHere are some _before_ and _afters_ to give you an idea of the kind of code transformations that `overwait` enables:\n\n\u003ctable\u003e\n  \u003ctr\u003e\n    \u003cth\u003eBefore...\u003c/th\u003e\n    \u003cth\u003e\u003cb\u003e...with Overwait!\u003c/b\u003e\u003c/th\u003e\n  \u003c/tr\u003e\n  \u003ctr\u003e\n    \u003ctd\u003e\n\n```js\nconst res = await fetch('https://x.com');\nconst body = await res.json();\n```\n\n   \u003c/td\u003e\n    \u003ctd\u003e\n\n```js\nconst body = await fetchy('https://x.com').json();\n```\n\n   \u003c/td\u003e\n  \u003c/tr\u003e\n  \u003ctr\u003e\n    \u003ctd\u003e\n\n```js\n// Not a specific db library, just an example\nconst conn = await db.conn('mydb');\nconst cursor = await conn.query('SELECT A');\nconst row = await cursor.getRow();\nconst value = await row.A;\n```\n\n   \u003c/td\u003e\n    \u003ctd\u003e\n\n```js\nconst value = await db.conn('mydb')\n                      .query('SELECT A')\n                      .getRow().A;\n```\n\n   \u003c/td\u003e\n  \u003c/tr\u003e\n  \u003ctr\u003e\n    \u003ctd\u003e\n\n```js\nconst [fileHandle] = await showOpenFilePicker();\nconst file = await fileHandle.getFile();\n```\n\n   \u003c/td\u003e\n    \u003ctd\u003e\n\n```js\nconst file = await showOpenFilePicker()[0].getFile();\n```\n\n   \u003c/td\u003e\n  \u003c/tr\u003e\n\u003c/table\u003e\n\n\n### Other cool things!\n\nWhen using `overwait` to traverse a property chain, we automatically wrap the `this` value in functions that are executed as a part of that traversal.\n\nThis fact allows you to write code like this:\n\n```js\nconst getValueFooBar = async function() {\n  // We don't need concern ourselves if\n  // `this`, `foo`, or `bar` are some mix of promises:\n  return await this.foo.bar;\n};\n```\n\nThen when using that function in an object, it just works:\n```js\n  const obj = overwait({\n    foo: Promise.resolve({\n      bar: Promise.resolve('hi there!')\n    })\n    value: getValueFooBar\n  });\n\n  await obj.value(); //=\u003e 'hi there!';\n```\n\n## But, Jon, I don't want to use `await`!\n\nNo `await`? No problem!\n\nBecause `await` is just syntactic sugar for `then`, the way the library works actually allows you to `then` to your hearts content.\n\nWhat this means is that to `overwait` this:\n\n```js\nawait promise1.promise2.promise3;\n/*...stuff what comes after...*/\n```\n\nIs identical to this:\n\n```js\npromise1.promise2.promise3.then(() =\u003e {\n/*...stuff what comes after...*/\n});\n```\n\n...and it just works!\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjwplayer%2Foverwait","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjwplayer%2Foverwait","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjwplayer%2Foverwait/lists"}