{"id":19353535,"url":"https://github.com/elldritch/promisebacker","last_synced_at":"2026-05-15T17:35:45.474Z","repository":{"id":25203505,"uuid":"28627317","full_name":"elldritch/promisebacker","owner":"elldritch","description":"A callback-to-promise-and-back adapter.","archived":false,"fork":false,"pushed_at":"2014-12-31T06:50:37.000Z","size":132,"stargazers_count":1,"open_issues_count":0,"forks_count":1,"subscribers_count":0,"default_branch":"master","last_synced_at":"2025-10-24T08:43:10.947Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"CoffeeScript","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/elldritch.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":"2014-12-30T10:47:15.000Z","updated_at":"2015-05-05T14:24:45.000Z","dependencies_parsed_at":"2022-09-10T10:38:25.498Z","dependency_job_id":null,"html_url":"https://github.com/elldritch/promisebacker","commit_stats":null,"previous_names":["ilikebits/promisebacker"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/elldritch/promisebacker","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/elldritch%2Fpromisebacker","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/elldritch%2Fpromisebacker/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/elldritch%2Fpromisebacker/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/elldritch%2Fpromisebacker/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/elldritch","download_url":"https://codeload.github.com/elldritch/promisebacker/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/elldritch%2Fpromisebacker/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":33073379,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-15T11:35:32.926Z","status":"ssl_error","status_checked_at":"2026-05-15T11:35:31.362Z","response_time":103,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"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":[],"created_at":"2024-11-10T04:43:12.212Z","updated_at":"2026-05-15T17:35:45.445Z","avatar_url":"https://github.com/elldritch.png","language":"CoffeeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Promisebacker\nWraps an asynchronous function that either takes a callback or returns a promise, and allows it to do both.\n\n**Note:** Promisebacker is still under development and not yet ready for production systems. Releases are stable but the API is subject to rapidly change.\n\n## Installation\n`npm install promisebacker`\n\n## Example\n```js\nvar Promise = require('promise') // Any Promises/A+ compliant library will do.\n  , promisebacker = require('promisebacker');\n\nvar takes_callback = function(arg1, arg2, callback) {\n  // Does something...\n  var error = false;\n\n  // Asynchronously invokes callback.\n  setTimeout(function() {\n    if (error){\n      return callback('uh oh!');\n    }\n    callback(null, 'hello world!');\n  }, 3000);\n};\n\nvar returns_promise = function(arg1, arg2) {\n  // Does something...\n  var error = false;\n\n  // Returns promise that resolves asynchronously.\n  return new Promise(function(resolve, reject) {\n    setTimeout(function() {\n      if (error) {\n        return reject('uh oh!');\n      }\n      resolve('hello world!');\n    }, 3000);\n  });\n};\n\nvar wrapped_callback = promisebacker(takes_callback);\n\n// Now we can pretend this returns a promise...\nwrapped_callback('alas', 'poor yorick')\n  .then(function(result) {\n    // result == 'hello world!'\n  });\n\n// ...or we can continue using it as a callback!\nwrapped_callback('alas', 'poor yorick', function(err, result) {\n  // err == null\n  // result == 'hello world!'\n});\n\n// And we can do the same for functions that return promises.\nvar wrapped_promise = promisebacker(returns_promise);\n\nwrapped_promise('alas', 'poor yorick')\n  .then(function(result) {\n    // result == 'hello world!'\n  });\n\nwrapped_promise('alas', 'poor yorick', function(err, result) {\n  // err == null\n  // result == 'hello world!'\n});\n\n```\n\n## Usage Notes\n`Promisebacker(Function target)` assumes that you're trying to use a callback if the last argument passed is a `Function` of arity at least 2. If you want to force it to return promises, use `Promisebacker.toPromise` instead.\n\n## API Reference\nWe define a function to take a _node-style callback_ (a _nodeback_) if it accepts a `Function` of arity at least 2 as its last argument and invokes that function whenever it finishes running. When invoking its callback, it must pass an error value as its first argument which must be truthy if and only if an error has occurred.\n\n##### `Promisebacker(Function target [, Object options])` -\u003e `Function`\nWraps `target` such that it can either take a callback or return a promise.\n* `target` must either return a promise or take nodebacks.\n* `options` is an optional object with options.\n\nIf `target` takes nodebacks and calls its callback with multiple success values, the fulfillment value will be an array of them.\n\nSee the `bluebird` documentation for [promisification](https://github.com/petkaantonov/bluebird/blob/master/API.md#promisification) for details.\n\n###### Option: `Object scope` (default: N/A)\nIf you pass a `scope`, then `target` will have its `this` bound to `scope` (i.e. as if it were being called as `scope.target`).\n\n###### Option: `Boolean spread` (default: `false` if nodeback is of arity at most 2, `true` otherwise)\nSome nodebacks expect more than 1 success value but there is no mapping for this in the promise world. If `spread` is specified, the nodeback is called with multiple values when the promise fulfillment value is an array:\n\n```js\nvar example = Promisebacker(Promise.resolve);\nexample([1, 2, 3], function(err, result) {\n  // err == null\n  // result == [1, 2, 3]\n});\n\nvar another = Promisebacker(Promise.resolve, {spread: true});\nanother([1, 2, 3], function(err, a, b, c) {\n  // err == null\n  // a == 1, b == 2, c == 3\n});\n```\n\n##### `Promisebacker.toPromise(Function target [, Object options])` -\u003e `Function`\nSame as above, but will always return a `Promise` even if the last argument is a `Function` of arity at least 2.\n\n\u003c!--\n##### `Promisebacker.all(Object target [, Object options])` -\u003e `Object`\nWraps all methods of `target` by going through the object's properties and creating an async equivalent of each function on the object and its prototype chain. The promisified method name will be the original method name suffixed with \"Async\".\n\nSee the `bluebird` documentation for [promisifyAll](https://github.com/petkaantonov/bluebird/blob/master/API.md#promisepromisifyallobject-target--object-options---object) for details.\n\n###### Option: `String suffix`\nDefine a custom suffix for wrapped methods.\n\n###### Option: `Function\u003cString name, Function func, Object target\u003e filter -\u003e Boolean`\nDefine a custom filter to select which methods to wrap:\n\n```js\nPromise.promisifyAll(..., {\n  filter: function(name, func, target) {\n    // name = the property name to be promisified without suffix\n    // func = the function\n    // target = the target object where the promisified func will be put with name + suffix\n    // return boolean\n  }\n});\n```\n\n###### Option: `promisifier`\nDefine a custom promisifier, so you could promisifyAll e.g. the chrome APIs used in Chrome extensions. See the `bluebird` documentation for [promisifyAll](https://github.com/petkaantonov/bluebird/blob/master/API.md#promisepromisifyallobject-target--object-options---object) for details.\n--\u003e\n\n## License\n\n\u0026copy; 2014 Lehao Zhang. Released under the terms of the MIT license.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Felldritch%2Fpromisebacker","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Felldritch%2Fpromisebacker","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Felldritch%2Fpromisebacker/lists"}