{"id":16323098,"url":"https://github.com/danielstjules/async-class","last_synced_at":"2025-07-04T02:36:55.174Z","repository":{"id":57185491,"uuid":"42383045","full_name":"danielstjules/async-class","owner":"danielstjules","description":"Cleaner ES6 async class methods","archived":false,"fork":false,"pushed_at":"2017-03-02T19:04:06.000Z","size":11,"stargazers_count":22,"open_issues_count":0,"forks_count":7,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-06-05T01:10:50.695Z","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/danielstjules.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":"2015-09-13T04:00:55.000Z","updated_at":"2018-05-31T08:55:38.000Z","dependencies_parsed_at":"2022-09-06T04:11:08.306Z","dependency_job_id":null,"html_url":"https://github.com/danielstjules/async-class","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"purl":"pkg:github/danielstjules/async-class","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/danielstjules%2Fasync-class","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/danielstjules%2Fasync-class/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/danielstjules%2Fasync-class/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/danielstjules%2Fasync-class/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/danielstjules","download_url":"https://codeload.github.com/danielstjules/async-class/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/danielstjules%2Fasync-class/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":263434926,"owners_count":23466048,"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-10T22:53:57.321Z","updated_at":"2025-07-04T02:36:55.150Z","avatar_url":"https://github.com/danielstjules.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# async-class\n\nCleaner ES6 async class methods for Node 4.0.0+. A solution to using promises\nand coroutines with classes without the overhead of babel, or the need to adopt\nunimplemented syntax and features, until v8/node supports ES7 async/await.\n\n[![Build Status](https://travis-ci.org/danielstjules/async-class.svg?branch=master)](https://travis-ci.org/danielstjules/async-class)\n\n## Installation\n\n```\nnpm install --save async-class\n```\n\n## Overview\n\nUsing only ES6 features, how would you achieve a class like the following?\n\n``` javascript\n'use strict';\n\nclass FakeDataStore {\n  constructor() {\n    this.store = new Map();\n  }\n\n  async setAsync(key, value) {\n    this.store.set(key, value);\n    return await Promise.resolve(key);\n  }\n}\n```\n\nYou'd use libraries that offer coroutine functionality like `co` or `bluebird`.\nHowever, there's no way to decorate those methods with ES6. Without the ES6\nclass sugar, we'd like to achieve the following:\n\n``` javascript\n'use strict';\nlet Promise = require('bluebird');\n\nfunction FakeDataStore {\n  this.store = new Map();\n}\n\nFakeDataStore.prototype.setAsync = Promise.coroutine(function*(key, value) {\n  this.store.set(key, value);\n  return yield Promise.resolve(key);\n};\n```\n\nThat's where this library comes in. Using it is simple:\n\n``` javascript\n'use strict';\nlet wrap = require('async-class').wrap;\n\nclass FakeDataStore {\n  constructor() {\n    this.store = new Map();\n  }\n\n  *setAsync(key, value) {\n    this.store.set(key, value);\n    return yield Promise.resolve(key);\n  }\n}\n\nmodule.exports = wrap(FakeDataStore);\n```\n\nClean ES6 classes and async methods!\n\n## API\n\n#### async-class.wrap(klass [, methodNames])\n\nWraps static and instance methods whose name ends with Async, or are\nGeneratorFunctions. Any GeneratorFunction is wrapped with\nbluebird.coroutine(), and others with bluebird.method(). Accepts an optional\narray of method names, wrapping only those found in the array, and disabling\nthe Async suffix check. Returns the class.\n\n#### async-class.wrapStaticMethods(klass [, methodNames])\n\nWraps static methods whose name ends with Async or are GeneratorFunctions.\nAny GeneratorFunction is wrapped with bluebird.coroutine(), and others with\nbluebird.method(). Accepts an optional array of method names, wrapping only\nthose found in the array, and disabling the Async suffix check. Returns the\nclass.\n\n#### async-class.wrapInstanceMethods(klass [, methodNames])\n\nWraps instance methods whose name ends with Async, or are GeneratorFunctions.\nAny GeneratorFunction is wrapped with bluebird.coroutine(), and others with\nbluebird.method(). Accepts an optional array of method names, wrapping only\nthose found in the array, and disabling the Async suffix check. Returns the\nclass.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdanielstjules%2Fasync-class","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdanielstjules%2Fasync-class","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdanielstjules%2Fasync-class/lists"}