{"id":13739422,"url":"https://github.com/MatAtBread/fast-async","last_synced_at":"2025-05-08T19:33:59.778Z","repository":{"id":57232917,"uuid":"44692260","full_name":"MatAtBread/fast-async","owner":"MatAtBread","description":null,"archived":false,"fork":false,"pushed_at":"2018-10-08T10:47:10.000Z","size":70,"stargazers_count":605,"open_issues_count":6,"forks_count":21,"subscribers_count":12,"default_branch":"master","last_synced_at":"2024-05-21T14:23:50.464Z","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/MatAtBread.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":"2015-10-21T17:18:58.000Z","updated_at":"2024-01-04T16:01:42.000Z","dependencies_parsed_at":"2022-09-04T23:00:44.928Z","dependency_job_id":null,"html_url":"https://github.com/MatAtBread/fast-async","commit_stats":null,"previous_names":[],"tags_count":11,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MatAtBread%2Ffast-async","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MatAtBread%2Ffast-async/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MatAtBread%2Ffast-async/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MatAtBread%2Ffast-async/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/MatAtBread","download_url":"https://codeload.github.com/MatAtBread/fast-async/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253135469,"owners_count":21859648,"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-08-03T04:00:33.811Z","updated_at":"2025-05-08T19:33:59.504Z","avatar_url":"https://github.com/MatAtBread.png","language":"JavaScript","readme":"fast-async\n==========\n\n'fast-async' is a _Babel_ plugin that implements the ES7 keywords `async` and `await` using syntax transformation\nat compile-time, rather than generators.\n\nFor _Babel v6.x.x_ install **fast-async@6**\nFor _Babel v7.x.x_ install **fast-async@7**\nNB: Babel 7 is in beta. The core nodent functionality is due to be included in Babel 7 release - see https://github.com/babel/babel/pull/7076\n\nThe main reason for using 'fast-async' as opposed to Babel's default implementation of async/await is\nperformance (https://github.com/MatAtBread/nodent#performance) - it's 3-4 times faster in a browser/node, and\nas much as 10 times faster on a mobile browsers, mainly due to avoiding generators (and therefore regenerator).\n\nThere's a simple test (that just makes sure the plugin works and generates code that runs). More complete\ntest coverage is included with nodent.\n\nBecause Babel parses the code, the ES7 extensions possible with nodent (`await` anywhere, `async return` and `async throw`) are not supported, however full implementation of `async function` containing `await` expressions is implemented.\n\nFor _Babel v5.x.x_ install fast-async@1.0.3\n\n\u003e v6.1.x\nfast-async@\u003e=6.1.0 can use nodent v2 or v3 (and acorn v3 or v4). Nodent v3 has the option of generating code with Promises which needs no runtime at all, at the cost of size and speed. v6.1.x can also reference the runtime via an import (useRuntimeModule option), rather than include the source inline.\n\nInstall\n-------\n```bash\nnpm install fast-async --save\n```\n\nUsage\n-----\n\nJust include the plugin to the babel options. Minimal `.babelrc` example:\n```js\n{\n  \"plugins\": [\"fast-async\"]\n}\n```\n\n**N.B.:** Starting in Babel v7, you'll need to prefix plugin names that do not begin with the `babel-plugin-` prefix with a `module:` directive:\n\n```js\n{\n  \"plugins\": [\"module:fast-async\"]\n}\n```\n\nThat's all. Neither `babel-plugin-transform-runtime` nor `babel-polyfill` required. Your application, once compiled, will probably needs nodent's runtime = see [below](#runtimepattern).\n\nWith options:\n```js\n{\n  \"plugins\": [\n    [\"fast-async\", {\n      \"env\": {\n      \t\"log\":false\n      },\n      \"compiler\": {\n        \"promises\": true,\n        \"generators\": false\n      },\n      \"runtimePattern\":null,\n      \"useRuntimeModule\":false\n    }]\n  ]\n}\n```\n\nThe option `spec` sets the compiler up to produce the most spec-compatible output (at the expense of some performance) by using the `wrapAwait`, `noRuntime` and `promises` options. Since `noRuntime` is specified, no runtime options are required.\n\n```js\n{\n  \"plugins\": [\n    [\"fast-async\", {\n      \"spec\":true\n    }]\n  ]\n}\n```\n\n\nTest\n----\nFrom the installation directory (e.g. node_modules/fast-async):\n```bash\nnpm test\n```\nOptions\n-------\nThe plugin accepts the following options object, which itself is optional, as are all members. These are based on the options in nodent,\nbut since much of the parsing is done by Babel some are unused.\n\n```js\nenv:{\n  log:function(string),        // Supplied routine to emit transformation warnings. Default: console.log\n},\ncompiler:{\n  promises:true    // Use nodent's \"Promises\" mode. Set to false if your runtime environment does not support Promises (default: true)\n},\nruntimePattern:null,     // See below\nuseRuntimeModule:false  // See below\n```\n_NB_: As of v6.3.x, the `env` options `augmentObject`,`dontMapStackTraces` and `dontInstallRequireHook:false` are no longer impemented or required. These modified the execution environment of the compiler (as opposed to the runtime environment of the code generated) and consequently had no purpose.\n\nFor more information on the compiler options, see [ES7 and Promises](https://github.com/matatbread/nodent#es7-and-promises) in the nodent documentation.\n\n\u003e 6.1.x\nThe dontMapStackTraces now defaults to `true` as having both nodent and babel map stack traces doesn't work well\n\nruntimePattern\n--------------\nBy default, fast-async will put the nodent runtime into every file containing an `async` function or `await` expression.\nIf your project is made up of more than one file, the constant redefinition of the runtime is a waste of time and space. You can\nspecify that you want the runtime in particular file(s) by setting the 'runtimePattern' to a regular expression (in quotes).\nOnly files that match the regular expression will have the runtime defined (which is global, so you only need it once).\n\nNote: At least one of the file(s) matching the \"runtimePattern\" must use either `await` or `async` as the runtime function (or `require('nodent-runtime')` if you set `\"useRuntimeModule\":true`) is only included for files that reference it.\n\nFor example:\n\n```js\n\"babel\": {\n  \"plugins\": [\n    \"syntax-async-functions\",\n    [\"fast-async\",{\n       \"runtimePattern\":\"test-input\\\\.js\"\n    }]\n  ]\n}\n```\nAlternatively, if you set runtimePattern to `\"directive\"`, the statement `\"use runtime-nodent\";` will be replaced with the runtime during compilation. Please note, that statement should be at very top of your module, as it should be parsed as directive, not as statement.\n\n\u003e v6.1.x\nIf you specify the option `\"useRuntimeModule\":true`, the runtime is not included directly as source, but via an import of [nodent-runtime](https://github.com/MatAtBread/nodent-runtime), which is typically resolved to `require()` by babel. The nodent-runtime module must be added as a dependency in your target project. The runtime need only be included once in your entire project, and should precede any code that uses async or await.\n\nPromises polyfill\n--------------\nThe purpose of `fast-async` is to transform the `async` and `await` into code which can be run in environments that don't support these keywords. With `promises: false` option, the transformed code will not reference the `Promise` global object for its internal logic, however if you use `Promise` in your code, it will be left as is. Therefore, you still need to install a _polyfill_ if you want to use this plugin to transpile code for environments without the `Promise` support.\n\nFor example, with `Webpack`, you can do it by using `webpack.ProvidePlugin`:\n\n```js\n// npm install zousan\n\nconst config = {\n  // ...\n  plugins: {\n    new webpack.ProvidePlugin({\n      Promise: 'zousan',\n    }),\n  },\n}\n```\n\nUseful Links\n------------\n\n* [nodent](https://github.com/MatAtBread/nodent)\n* [Babel plugins](http://babeljs.io/docs/advanced/plugins/)\n\nOnline performance checkers:\n\n* [nodent](http://nodent.mailed.me.uk/#function%20pause()%20%7B%0A%20%20%20%20return%20new%20Promise(function%20(%24return%2C%20%24error)%20%7B%0A%20%20%20%20%20%20%20%20setTimeout(function%20()%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20return%20%24return(0)%3B%0A%20%20%20%20%20%20%20%20%7D%2C%200)%3B%0A%20%20%20%20%7D)%3B%0A%7D%0A%0Aasync%20function%20doNothing()%20%7B%0A%20%20%20%20return%3B%0A%7D%0A%0Aasync%20function%20test()%20%7B%0A%20%20%20%20var%20t%20%3D%20Date.now()%3B%0A%20%20%20%20for%20(var%20j%20%3D%200%3B%20j%20%3C%2050%3B%20j%2B%2B)%20%7B%0A%20%20%20%20%20%20%20%20for%20(var%20i%20%3D%200%3B%20i%20%3C%202000%3B%20i%2B%2B)%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20await%20doNothing()%3B%0A%20%20%20%20%20%20%20%20%7D%0A%20%20%20%20%20%20%20%20await%20pause()%3B%0A%20%20%20%20%7D%0A%20%20%20%20return%20Date.now()%20-%20t%3B%0A%7D%0A%0Atest().then(alert)%3B%0A~options~%7B%22mode%22%3A%22promises%22%2C%22promiseType%22%3A%22Zousan%22%2C%22noRuntime%22%3Atrue%2C%22es6target%22%3Afalse%2C%22wrapAwait%22%3Afalse%2C%22spec%22%3Afalse%7D) 248ms\n* [babel](https://babeljs.io/repl/#?babili=false\u0026evaluate=true\u0026lineWrap=false\u0026presets=es2015%2Cstage-3\u0026targets=\u0026browsers=\u0026builtIns=false\u0026debug=false\u0026experimental=true\u0026loose=false\u0026spec=false\u0026code_lz=GYVwdgxgLglg9mABABwIYgM4FMAUBKRAbwChEzEAnLKECpMLAd0QAUK4BbGbHUSWBIhwASKjToAaRMKwV2FAiXLLE2KABUYHLHBBRe4aPCT4ipFRbG0ko6tZwAGPAG5zFgL5Snr5e5fF3YmJUDABPSEQ-I0EAEzgAOTgoAAsYMABzUyVyKzpXQOCwiKiBJCgsDH1FN0QAN1QKRChEAF5EABFUcoA6MDhGfB9yYDhGnHrGgCtWxAdnRGmAHkQAVjmFgGoN6osyEbGJxBgZ9ePlgCYHK_mYLZ3d5VRGVBhmuMSUtMz_B8CHp5ezTQmFwP3IfxydjoHS6WF6_VMAFomvkguVKvhuiksGAcKgADayKD-IA) 440ms - 1.8x slower\n* [traceur](https://google.github.io/traceur-compiler/demo/repl.html#%2F%2F%20Options%3A%20--annotations%20--array-comprehension%20--async-functions%20--async-generators%20--exponentiation%20--export-from-extended%20--for-on%20--generator-comprehension%20--member-variables%20--proper-tail-calls%20--require%20--symbols%20--types%20%0Afunction%20pause()%20%7B%0A%20%20%20%20return%20new%20Promise(function%20(%24return%2C%20%24error)%20%7B%0A%20%20%20%20%20%20%20%20setTimeout(function%20()%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20return%20%24return(0)%3B%0A%20%20%20%20%20%20%20%20%7D%2C%200)%3B%0A%20%20%20%20%7D)%3B%0A%7D%0A%0Aasync%20function%20doNothing()%20%7B%0A%20%20%20%20return%3B%0A%7D%0A%0Aasync%20function%20test()%20%7B%0A%20%20%20%20var%20t%20%3D%20Date.now()%3B%0A%20%20%20%20for%20(var%20j%20%3D%200%3B%20j%20%3C%2050%3B%20j%2B%2B)%20%7B%0A%20%20%20%20%20%20%20%20for%20(var%20i%20%3D%200%3B%20i%20%3C%202000%3B%20i%2B%2B)%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20await%20doNothing()%3B%0A%20%20%20%20%20%20%20%20%7D%0A%20%20%20%20%20%20%20%20await%20pause()%3B%0A%20%20%20%20%7D%0A%20%20%20%20return%20Date.now()%20-%20t%3B%0A%7D%0A%0Atest().then(alert)%3B%0A) 1388ms - 5.6x slower\n","funding_links":[],"categories":["📦 Legacy \u0026 Inactive Projects","Plugins"],"sub_categories":["General Plugins"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FMatAtBread%2Ffast-async","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FMatAtBread%2Ffast-async","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FMatAtBread%2Ffast-async/lists"}