{"id":20195838,"url":"https://github.com/ralphv/hybrid-callback","last_synced_at":"2025-06-16T02:04:11.410Z","repository":{"id":78065166,"uuid":"81927569","full_name":"ralphv/hybrid-callback","owner":"ralphv","description":"A very simple node.js hybrid callback pattern library","archived":false,"fork":false,"pushed_at":"2017-02-14T12:24:17.000Z","size":14,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-02-24T02:53:26.697Z","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":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ralphv.png","metadata":{"files":{"readme":"README.md","changelog":"ChangeLog","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2017-02-14T09:19:40.000Z","updated_at":"2017-02-14T09:21:39.000Z","dependencies_parsed_at":"2023-03-02T13:00:31.497Z","dependency_job_id":null,"html_url":"https://github.com/ralphv/hybrid-callback","commit_stats":{"total_commits":13,"total_committers":1,"mean_commits":13.0,"dds":0.0,"last_synced_commit":"d804c9a05d854223778fef391b136c0282ccc0b1"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ralphv%2Fhybrid-callback","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ralphv%2Fhybrid-callback/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ralphv%2Fhybrid-callback/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ralphv%2Fhybrid-callback/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ralphv","download_url":"https://codeload.github.com/ralphv/hybrid-callback/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":241629772,"owners_count":19993710,"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-14T04:19:22.258Z","updated_at":"2025-03-03T08:13:10.647Z","avatar_url":"https://github.com/ralphv.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"## hybrid-callback - A very simple node.js hybrid callback pattern library\n\n[![NPM](https://nodei.co/npm/hybrid-callback.png?mini=true)](https://nodei.co/npm/hybrid-callback/)\n\n[![Build Status](https://travis-ci.org/ralphv/hybrid-callback.svg?branch=master)](https://travis-ci.org/ralphv/hybrid-callback)\n[![Coverage Status](https://coveralls.io/repos/github/ralphv/hybrid-callback/badge.svg?branch=master)](https://coveralls.io/github/ralphv/hybrid-callback?branch=master)\n        \n* [What is it?](#what-is-it)\n* [Getting started](#getting-started)\n* [Usage](#usage)\n* [License](#License)\n* [Changelog](#Changelog)\n\n## What is it\n\nNode.js has the async programming model. Most of the function calls have the last parameter as a callback parameter, which is a function reference.\nUsually you have to deal with each callback's error/success state, this duplicates code a lot and creates the callback hell.\n\nThere are different options to deal with callbacks including promises. hybrid-callback is a very simple pattern where you wrap the callback with a function call. Wraping the callback will allow you to write your code for success states only and error states will bubble up as needed.\n\n## Getting started\n\n    $ npm install --save hybrid-callback\n\n## Usage\n\nInstead of writing\n\n```javascript\nfunction f1(data, cb) {\n  f2(data, function(err, data) {\n    if(err) {\n      return cb(err); // Each Async function/block needs to check for errors\n    }\n    else {\n      doSomethingInDb(data, function(err, data) {\n        if(err) { // Deal with error\n          return cb(err);\n        }\n        else {\n          processData(data, function(err, finalData) {\n            if(err) {  // Deal with errors in every step, a lot of repeated code, chance to introduce bugs.\n              return cb(err);\n            }\n            else {\n              cb(null, finalData);\n            }\n          });\n        }\n      });\n    }\n  });\n}\n```\n\nWrite\n\n```javascript\nconst hcb = require(\"hybrid-callback\");\n\nfunction f1(data, cb) {\n  f2(data, hcb(cb, function(data) { // Wrap your cb with hcb, handle the success state only\n    doSomethingInDb(data, hcb(cb, function(data) { // Any error state along the way will bubble up automatically \n      processData(data, hcb(cb, function(finalData) {\n        cb(null, finalData); // Simpler code, more readable, less bugs from error handling\n      }));\n    }));\n  }));\n}\n```\n\n### License\n\nhybrid-callback is licensed under the [MIT](https://github.com/ralphv/hybrid-callback/raw/master/LICENSE).\n\n### Changelog\n\n* 1.0.0: Initial version (simplified from cb-result library)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fralphv%2Fhybrid-callback","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fralphv%2Fhybrid-callback","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fralphv%2Fhybrid-callback/lists"}