{"id":18687343,"url":"https://github.com/junosuarez/fallback","last_synced_at":"2025-04-12T05:27:03.480Z","repository":{"id":6135458,"uuid":"7363940","full_name":"junosuarez/fallback","owner":"junosuarez","description":"npm module: retry a function with a series of arguments until one works","archived":false,"fork":false,"pushed_at":"2013-07-24T17:08:03.000Z","size":55,"stargazers_count":5,"open_issues_count":0,"forks_count":3,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-10T15:36:26.878Z","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":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/junosuarez.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2012-12-29T07:04:40.000Z","updated_at":"2022-04-07T13:38:09.000Z","dependencies_parsed_at":"2022-09-14T18:50:39.681Z","dependency_job_id":null,"html_url":"https://github.com/junosuarez/fallback","commit_stats":null,"previous_names":["jden/fallback"],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/junosuarez%2Ffallback","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/junosuarez%2Ffallback/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/junosuarez%2Ffallback/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/junosuarez%2Ffallback/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/junosuarez","download_url":"https://codeload.github.com/junosuarez/fallback/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248521387,"owners_count":21118062,"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-07T10:32:30.726Z","updated_at":"2025-04-12T05:27:03.441Z","avatar_url":"https://github.com/junosuarez.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# fallback\nretry a function with a series of arguments until one works\n\n## usage\n```js\n// run this in the repo: `npm install; node sample.js`\n// test a list of servers for a response\nvar fallback = require('fallback')\nvar request = require('request')\n\nvar servers = ['http://foo.baz', 'http://google.com', 'http://fail']\n\nfallback(servers, function (server, callback) {\n  console.log('trying server at ' + server)\n  request(server, function (err, response) {\n    if (err || response.statusCode \u003e= 400) {\n      // try the next server\n      return callback()\n    }\n    callback(null, response.statusCode)\n  })\n}, function (err, result, server) {\n  if (err) {\n    console.error(err)\n    process.exit(1)\n  }\n  if (result) {\n    console.log('server ' + server + ' returned: ' + result)\n  } else {\n    console.log('no servers returned successfully')\n  }\n})\n```\n\nreturns\n\n    trying server at http://foo.baz\n    trying server at http://google.com\n    server http://google.com returned: 200\n\n## API\n\n`fallback: (array: Array, iteratorFunction: IteratorFunction, outerCallback: OuterCallback) =\u003e void`\n\nCall `fallback` with an array of alternative values to be used as arguments on\n`iteratorFunction`.\n\n`IteratorFunction: (arrayItem, callback: (err: Error, result) =\u003e void) =\u003e void`\n\n`iteratorFunction` is an async function of\n`function (arrayItem, callback)`, where `callback` is a normal node-style\n`callback(err, result)` continuation. **Note** that if an error is given to\n`callback`, the entire fallback sequence will terminate early. This should be\nused for unrecoverable errors. To indicate that the operation on the current\n`arrayItem` did not succeed and that the next one should be tried, `callback`\nshould be invoked with a `null` error and an `undefined` or `false` value for\n`result`. A `result` value of `null` has the semantics that \"the operation\nsucceeded (and therefore further fallbacks should not be tried), and there\nwas no result value\".\n\n`OuterCallback: (err: Error, result, arrayItem, array: Array) =\u003e void`\n\nIn `outerCallback`, there are three possible return states:\n`err` is not undefined: there was an unrecoverable error when executing the\nfallback sequence.\n`result` is `false`: none of the fallback alternatives were successful.\n`arrayItem` is null, and `array` contains the original array.\n`result` is not `false`: one of the fallback alternatives was successful.\n`result` contains the `result` value of that operation and `arrayItem`\ncontains the value that was used in the successful operation. `array`\ncontains the original array.\n\nThe parameters for `outerCallback` are similar to those in the callback for\n`Array.prototype.map` - first the value, then an index, then the original\ncollection.\n\n## isn't this the same as `async.some`?\n\nSort of, but `fallback` has much better semantics, and it uses normal\nnode-style async callbacks (eg, `callback(err, result)` ) for composability.\n\n## installation\nwith npm\n\n    $ npm install fallback\n\n## contributors\n\n- jden \u003cjason@denizac.org\u003e\n- Nathan Peck \u003cnathan@storydesk.com\u003e\n\n## license\nMIT\n(c) MMXIII jden - Jason Denizac \u003cjason@denizac.org\u003e\nhttp://jden.mit-license.org/2012","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjunosuarez%2Ffallback","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjunosuarez%2Ffallback","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjunosuarez%2Ffallback/lists"}