{"id":35106974,"url":"https://github.com/polygonplanet/jquery-async-plugin","last_synced_at":"2026-05-18T20:06:08.777Z","repository":{"id":66222485,"uuid":"13046581","full_name":"polygonplanet/jquery-async-plugin","owner":"polygonplanet","description":"jQuery async plugin adds Deferred to handle like the Mochikit.Async.Deferred.","archived":false,"fork":false,"pushed_at":"2014-10-03T06:01:44.000Z","size":232,"stargazers_count":4,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-12-29T13:24:23.181Z","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":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/polygonplanet.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":"2013-09-23T20:38:48.000Z","updated_at":"2025-06-13T21:50:47.000Z","dependencies_parsed_at":"2023-02-20T00:20:28.728Z","dependency_job_id":null,"html_url":"https://github.com/polygonplanet/jquery-async-plugin","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/polygonplanet/jquery-async-plugin","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/polygonplanet%2Fjquery-async-plugin","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/polygonplanet%2Fjquery-async-plugin/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/polygonplanet%2Fjquery-async-plugin/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/polygonplanet%2Fjquery-async-plugin/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/polygonplanet","download_url":"https://codeload.github.com/polygonplanet/jquery-async-plugin/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/polygonplanet%2Fjquery-async-plugin/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":33189279,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-18T09:27:30.708Z","status":"ssl_error","status_checked_at":"2026-05-18T09:27:28.300Z","response_time":71,"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":"2025-12-27T18:20:06.864Z","updated_at":"2026-05-18T20:06:08.772Z","avatar_url":"https://github.com/polygonplanet.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"jQuery async plugin\n===================\n\njQuery async plugin adds **Deferred** to handle like the [Mochikit.Async.Deferred](http://mochi.github.io/mochikit/doc/html/MochiKit/Async.html#fn-deferred).\n\nThis plugin adds the Deferred functions to jQuery.Deferred object, but it does not conflict with other plugins.\njQuery.Deferred keeps original functions.\njQuery object is added only **async** function object.\n\n\n## Installation\n\nInclude script after the jQuery library:\n\n```html\n\u003cscript src=\"/path/to/jquery.async.js\"\u003e\u003c/script\u003e\nor\n\u003cscript src=\"/path/to/jquery.async.min.js\"\u003e\u003c/script\u003e\n```\n\n$.async() is a shortcut function faster way of creating new Deferred sequence.\n\n```javascript\n$.async(function() {\n    console.log('Start Deferred chain');\n}).addCallback(function() {\n    console.log('End Deferred chain');\n});\n```\n\n## Usage\n\nThe basic usage is the same as the Mochikit.Async.Deferred.\n\n\nSimple Deferred chain:\n\n```javascript\nvar d = $.Deferred();\nd.addCallback(function() {\n    return 1;\n}).addCallback(function(res) {\n    console.log(res); // 1\n});\nd.callback();\n```\n\nUsing [succeed](http://mochi.github.io/mochikit/doc/html/MochiKit/Async.html#fn-succeed)():\n\n```javascript\n$.async.succeed(1).addCallback(function(res) {\n    return res + 1;\n}).addCallback(function(res) {\n    console.log(res); // 2\n});\n```\n\nPassing Values and Error handling:\n\n```javascript\n$.async(function() {\n    return 1;\n}).addCallback(function(res) {\n    console.log(res); // 1\n    throw new Error('error');\n}).addCallback(function(res) {\n    console.log('This message does not show');\n    return 'noop';\n}).addErrback(function(err) {\n    console.log(err); // error\n    return 'hello';\n}).addBoth(function(res) {\n    console.log(res); // hello\n});\n```\n\n## Function reference\n\n*Portions of this document are reference from MochiKit.*\n\n### $.Deferred() *Deferred*\n\nThe Deferred object usage is the same as the jQuery.Deferred.\n\n```javascript\nvar d = $.Deferred();\n```\n\nThe following callback methods has been added.\n\n#### [addCallback](http://mochi.github.io/mochikit/doc/html/MochiKit/Async.html#fn-deferred.prototype.addcallback)( *function* callback) *Deferred*\n\nAdd a single callback to the end of the callback sequence.\n\n#### [addErrback](http://mochi.github.io/mochikit/doc/html/MochiKit/Async.html#fn-deferred.prototype.adderrback)( *function* errback) *Deferred*\n\nAdd a single errback to the end of the callback sequence.\n\n#### [addBoth](http://mochi.github.io/mochikit/doc/html/MochiKit/Async.html#fn-deferred.prototype.addboth)( *function* func) *Deferred*\n\nAdd the same function as both a callback and an errback as the next element on the callback sequence. This is useful for code that you want to guarantee to run.\n\n#### [addCallbacks](http://mochi.github.io/mochikit/doc/html/MochiKit/Async.html#fn-deferred.prototype.addcallbacks)( *function* callback, *function* errback) *Deferred*\n\nAdd separate callback and errback to the end of the callback sequence. Either callback or errback may be null, but not both.\n\n#### [callback](http://mochi.github.io/mochikit/doc/html/MochiKit/Async.html#fn-deferred.prototype.callback)([ \\* result]) *Deferred*\n\nBegin the callback sequence with a non-Error result. Result may be any value except for a Deferred.\n\n#### [errback](http://mochi.github.io/mochikit/doc/html/MochiKit/Async.html#fn-deferred.prototype.errback)([ \\* result]) *Deferred*\n\nBegin the callback sequence with an error result. Result may be any value except for a Deferred.\n\n#### [cancel](http://mochi.github.io/mochikit/doc/html/MochiKit/Async.html#fn-deferred.prototype.cancel)() *Deferred*\n\nCancels a Deferred that has not yet received a value, or is waiting on another Deferred as its value.\n\n```javascript\nvar d = $.Deferred();\nd.addCallback() {\n    return 1;\n}).addCallback(res) {\n    console.log(res); // 1\n    throw 'ExampleError';\n}).addCallback(function() {\n    neverHappen();\n}).addErrback(function(err) {\n    console.log(err); // ExampleError\n}).addCallback(function() {\n    if (Math.random() * 10 \u003e 5) {\n        throw 'RandomError';\n    }\n    return 'random test';\n}).addBoth(function(res) {\n    console.log(res); // RandomError or 'random test'\n});\n// fire chain\nd.callback();\n```\n\n#### $.async( *function* func) *Deferred*\n\nA shortcut faster way of creating new Deferred sequence.\n\n```javascript\n$.async(function() {\n    console.log('Start Deferred chain');\n}).addCallback(function() {\n    console.log('End Deferred chain');\n});\n```\n\n#### $.async.[succeed](http://mochi.github.io/mochikit/doc/html/MochiKit/Async.html#fn-succeed)([ \\* result]) *Deferred*\n\nReturn a Deferred that has already had .callback(result) called.\n\n```javascript\n$.async.succeed(1).addCallback(function(res) {\n    console.log(res); // 1\n});\n```\n\n#### $.async.[fail](http://mochi.github.io/mochikit/doc/html/MochiKit/Async.html#fn-fail)([ \\* result]) *Deferred*\n\nReturn a Deferred that has already had .errback(result) called.\n\n```javascript\n$.async.fail(1).addErrback(function(err) {\n    console.log(err); // Error: 1\n});\n```\n\n#### $.async.[maybeDeferred](http://mochi.github.io/mochikit/doc/html/MochiKit/Async.html#fn-maybedeferred)( \\* func) *Deferred*\n\nCall a func with the given arguments and ensure the result is a Deferred.\n\n```javascript\nvar d = $.async.succeed(1);\nvar s = 'abc';\nvar random = (Math.random() * 10 \u003c 5);\n$.async.maybeDeferred( random ? d : s ).addCallback(function(res) {\n    console.log(res); // 1 or 'abc'\n});\n```\n\n#### $.async.maybeDeferreds( \\* ...args) *Array*\n\nReturn an array of Deferred instances.\n\n```javascript\nvar list = $.async.maybeDeferreds(\n    1, 2, 'foo', 'bar',\n    function() { return 5 },\n    $.async.succeed(100)\n);\nconsole.log(list); // [ 1, 2, ... (deferred instances) ]\nlist[0].addCallback(function(res) {\n    console.log(res); // 1\n});\n```\n\n#### $.async.[wait](http://mochi.github.io/mochikit/doc/html/MochiKit/Async.html#fn-wait)( *number* seconds[, \\* res]) *Deferred*\n\nReturn a new cancellable Deferred that will .callback(res) after at least seconds seconds have elapsed.\n\n```javascript\n// Called after 5 seconds.\n$.async.wait(5).addCallback(function() {\n    console.log('Begin wait() test');\n}).addCallback(function() {\n    return $.async.wait(2); // Wait 2 seconds.\n}).addCallback(function() {\n    console.log('End wait() test');\n});\n```\n\n#### $.async.[callLater](http://mochi.github.io/mochikit/doc/html/MochiKit/Async.html#fn-calllater)( *number* seconds, *funcion* func[, \\* args...]) *Deferred*\n\nCall func(args...) after at least seconds seconds have elapsed.\n\n```javascript\nvar value = null;\n// Called after 1 second.\n$.async.callLater(1, function() {\n    value = 'hoge';\n});\nconsole.log(value); // null\n$.async.callLater(1, function() {\n    console.log(value); // 'hoge'\n});\n```\n\n#### $.async.till( *function* cond) *Deferred*\n\nWait until the condition completed. If true returned, waiting state will end.\n\n```javascript\nconsole.log('Begin till');\n$.async.till(function() {\n    // wait until the DOM body element is loaded\n    if (!document.body) {\n        return false;\n    } else {\n        return true;\n    }\n}).addCallback(function() {\n    console.log('End till');\n    document.body.innerHTML += 'Hello';\n});\n```\n\n## License\n\nLicensed under the MIT license.\n\n## Authors\n\n* [polygon planet](https://github.com/polygonplanet) (twitter: [polygon_planet](http://twitter.com/polygon_planet))\n\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpolygonplanet%2Fjquery-async-plugin","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpolygonplanet%2Fjquery-async-plugin","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpolygonplanet%2Fjquery-async-plugin/lists"}