{"id":15736699,"url":"https://github.com/thejohnfreeman/await-observable","last_synced_at":"2025-03-31T04:40:41.316Z","repository":{"id":57165987,"uuid":"168420297","full_name":"thejohnfreeman/await-observable","owner":"thejohnfreeman","description":"Asynchronous functions for observables.","archived":false,"fork":false,"pushed_at":"2019-02-12T15:57:00.000Z","size":14,"stargazers_count":3,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-03-23T09:29:50.078Z","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/thejohnfreeman.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":"2019-01-30T21:44:46.000Z","updated_at":"2023-10-31T16:28:52.000Z","dependencies_parsed_at":"2022-08-30T15:10:28.810Z","dependency_job_id":null,"html_url":"https://github.com/thejohnfreeman/await-observable","commit_stats":null,"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thejohnfreeman%2Fawait-observable","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thejohnfreeman%2Fawait-observable/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thejohnfreeman%2Fawait-observable/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thejohnfreeman%2Fawait-observable/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/thejohnfreeman","download_url":"https://codeload.github.com/thejohnfreeman/await-observable/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246418699,"owners_count":20773935,"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-10-04T01:41:07.087Z","updated_at":"2025-03-31T04:40:41.294Z","avatar_url":"https://github.com/thejohnfreeman.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# await-observable\n\nAsynchronous functions for observables.\n\n[![npm](https://img.shields.io/npm/v/@thejohnfreeman/await-observable.svg)](https://www.npmjs.com/package/@thejohnfreeman/await-observable)\n[![bundle size](https://img.shields.io/bundlephobia/minzip/@thejohnfreeman/await-observable.svg?style=flat)](https://bundlephobia.com/result?p=@thejohnfreeman/await-observable)\n[![code style: Prettier](https://img.shields.io/badge/code_style-prettier-ff69b4.svg?style=flat)](https://github.com/prettier/prettier)\n[![build status](https://travis-ci.org/thejohnfreeman/await-observable.svg?branch=master)](https://travis-ci.org/thejohnfreeman/await-observable)\n\nA [longer version][] of the justification for this library is available on my\nblog. In brief, we're missing the observable equivalent of asynchronous\nfunctions. Chaining operators like `map`, `filter`, and `catchError` with\nobservables that yield a single value is as painful as chaining callbacks on\npromises. Asynchronous functions let us write asynchronous code in\na synchronous style, which is easier to read, write, and comprehend. Short of\nnative syntax like `async`/`await`, we can offer a decorator for generator\nfunctions.\n\n[longer version]: https://medium.com/@thejohnfreeman/escaping-pipeline-hell-38d962f66d31\n\n\n## Usage\n\n```typescript\nimport { async } from '@thejohnfreeman/await-observable'\n\nconst logIn = async(function*({ username, password }) {\n  try {\n    const token = yield ajax.getJSON(\n      'https://example.com/login', { username, password })\n    return { value: token }\n  } catch (cause) {\n    return { error: 'Wrong username or password.' }\n  }\n})\n\nconst observable = logIn({ username, password }) // Request not yet sent.\nconst subscription = observable.subscribe( // Request sent now.\n  ({ value }) =\u003e console.log('token', value),\n  ({ error }) =\u003e console.error('error', error),\n)\nsubscription.unsubscribe() // Request canceled.\n```\n\n## FAQ\n\n### Why did you name your export `async`?\n\nTo mimic asynchronous function syntax as closely as possible. If you don't\nlike that style, you can easily rename it:\n\n```typescript\nimport { async as myFavoriteName } from '@thejohnfreeman/await-observable'\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fthejohnfreeman%2Fawait-observable","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fthejohnfreeman%2Fawait-observable","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fthejohnfreeman%2Fawait-observable/lists"}