MatAtBread / fast-async

605 stars 21 forks source link

add options to select which parts of the runtime will be included #42

Closed tyrak closed 6 years ago

tyrak commented 6 years ago

When I load fast-async as a babel plugin with the following configuration {compiler: {noRuntime: false, promises: true}}, the runtime is included in the output file. Currently that runtime is 286 lines long (before minification) and includes things that I don't use, such as support for lazy thenables and the entire Zousan library. I suspect that only a small part of that is actually needed in my case. Is it possible to make fast-async include only a subset of the runtime?

matAtWork commented 6 years ago

Assuming you want to turn off the runtime, set noRuntime: true. That will generate code for Promises that doesn't reference the run-time at all.

matAtWork commented 6 years ago

As per issue #41, it feels like your default spec is not being found.

tyrak commented 6 years ago

As per issue #41, it feels like your default spec is not being found.

Actually changing the value of noRuntime does work, e.g. the runtime is appropriately included or excluded.

The reason I am making this request is the following: When I compare the output of noRuntime: false to noRuntime: true and specifically how they handle async functions, I find that I prefer the former because it avoids all those try .. catch blocks that the latter config creates. But if use the former config, the runtime will include code for lazy thenables and Zousan promises, which is a shame since I know that I will not use either of them.

matAtWork commented 6 years ago

If you really wanted to do that (Zousan is many, many times faster than Promises, so I wouldn't), I'd suggest rolling your own runtime. You only need to include it once, and it can be placed in a separate module (nodent-runtime)

tyrak commented 6 years ago

Ok, thanks, I might do just that.