{"id":16919046,"url":"https://github.com/rkh/deferrable","last_synced_at":"2025-08-09T21:14:30.362Z","repository":{"id":1010575,"uuid":"831265","full_name":"rkh/deferrable","owner":"rkh","description":"Callback indirection for JavaScript","archived":false,"fork":false,"pushed_at":"2010-08-11T18:38:39.000Z","size":112,"stargazers_count":4,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-03-20T22:50:16.388Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"ncsa","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/rkh.png","metadata":{"files":{"readme":"README.coffee.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":"2010-08-11T15:02:36.000Z","updated_at":"2023-11-30T02:16:14.000Z","dependencies_parsed_at":"2022-07-15T06:00:40.014Z","dependency_job_id":null,"html_url":"https://github.com/rkh/deferrable","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/rkh/deferrable","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rkh%2Fdeferrable","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rkh%2Fdeferrable/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rkh%2Fdeferrable/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rkh%2Fdeferrable/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/rkh","download_url":"https://codeload.github.com/rkh/deferrable/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rkh%2Fdeferrable/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":260251297,"owners_count":22981007,"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-13T19:42:47.204Z","updated_at":"2025-06-16T22:32:09.287Z","avatar_url":"https://github.com/rkh.png","language":"JavaScript","readme":"# Deferrable - Callback indirection for CoffeeScript\n*If you prefer JavaScript, see [README.md](http://github.com/rkh/deferrable/blob/master/README.md).*\n\nDeferrable adds a layer between you're own callbacks and the hooks calling them. You therefore can use a\ncallback waiting for multiple events to finish without nesting callbacks. This has the huge advantage of\nimproving concurrency as events can be processed simultaneously instead of sequentially.\n\n## Basic Usage\n\nTake this example:\n\n    showAnimation -\u003e loadContent -\u003e displayContent()\n\nIn that case the animation is happening totally asynchronously, but we don't take advantage of that.\nWe only start loading content when the animation has finished.\n\nOr would it be smart to load the content first?\n\n    loadContent -\u003e showAnimation -\u003e displayContent()\n\nIn that case some time would go by without any visible feedback for the user. Sure, the content comes\nright in after playing the animation. But what we really want it to load the content *while* playing the\nanimation. However, we need both the content to have arrived and the animation to be done *before* we can\ndisplay the new content:\n\n    d = new Deferrable\n    loadContent d.callback()\n    showAnimation d.callback()\n    d.onSuccess -\u003e displayContent()\n\nIt does not matter which event finishes first and whether that happens before or after calling `onSuccess`.\nIf both events finish, the `onSuccess` callback will be called exactly once.\n\nThis works with as many events as you like.\n\n## Complex Dependencies\n\nTake this code example:\n\n    deferrable  = new Deferrable\n    reusable    = deferrable.callback()\n    first deferrable.callback()\n    second reusable\n    third reusable\n    deferrable.onSuccess -\u003e something()\n\nIn that example `something` will be called as soon as the event `first` and either `second` or `third` have\nfinished.\n\nIt is also possible to have Deferrable depending on each other:\n\n    a = new Deferrable\n    b = new Deferrable\n    c = new Deferrable\n    document.onload = a.callback()\n    a.onSuccess b.callback()\n    b.onSuccess c.callback()\n\n## Passing Arguments\n\nYou probably want to access the arguments passed on by the events. If we take the first example: `loadContent`\nis probably handing over the body and header of an AJAX response. In order to do so, we have to name the callbacks:\n\n    deferrable = new Deferrable\n    loadContent deferrable.callback('content')\n    showAnimation deferrable.callback()\n    deferrable.onSuccess (results) -\u003e\n      [body, header] = results.content\n      displayContent body\n\n## Setup\nDownload the source from here or install via npm: `npm install deferrable`.\n\n### In the browser\nStore [deferrable.js](http://github.com/rkh/deferrable/blob/master/lib/deferrable.js) somewhere and load\ninto in your page by using `\u003cscript src='deferrable.js'\u003e\u003c/script\u003e`.\n\n### On the server\nOn Node.js and any other implementation allows replacing `exports`, you can simply do:\n\n    Deferrable = require 'deferrable'\n\nIf your platform does not support replacing `exports`, you can *always* use this:\n\n    Deferrable = require('deferrable').Deferrable\n\n## Running the tests\n\n### In the browser\nrun `rake build` and open `test/deferrable_test.html`.\n\n### On Node.js\nrun `rake test`.\n\n### On most CommonJS implementation\nrun `rake build` and open `test/deferrable_test.js`\n\n## Requirements\nSupported platforms:\n\n* Any common web browser with js support (Netscape 4.0 or later, Internet Explorer 5.5 or later, Opera 5.12 or later, Firefox 1.0 or later, Konqueror 3.1 or later, Safari, Chrome, ...)\n* Any CommonJS implementation supporting Modules 1.x (CoucheDB 0.11 or later, Ejscript 2.0 or later, Flusspferd, GPSEE, Narwhal 0.1 or later, Perserve, RingoJS, Smart Platform, SproutCore 1.1 or later, Wakanda, Yabble, node.js, v8cgi)\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frkh%2Fdeferrable","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frkh%2Fdeferrable","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frkh%2Fdeferrable/lists"}