MatAtBread / fast-async

605 stars 21 forks source link

Runtime as module #15

Closed SimonDegraeve closed 7 years ago

SimonDegraeve commented 7 years ago

Following the discussion in MatAtBread/nodent#60

FYI, noRuntime is nice, but it is a bit slower, mainly because .bind(this) is slow compared to $asyncbind(this), and the need to wrap async bodies in a try...catch causes de-optimization.

I think it would be nice to have an option to require the runtime as a module. Currently the choices are: directive, everywhere or in some file matching a regexp.

Something like babel-runtime:

const fn = async function(){}

Transforms into

require('nodent-runtime');
var fn = function fn() {
  return new Promise(function ($return, $error) {
    return $return();
  }.$asyncbind(this));
};

And throw if nodent-runtime is not in the package dependencies.

SimonDegraeve commented 7 years ago

I have a PR ready, adding this option and fixing #16 But the code style of this module is quiet inconsistent and there is no linter used, so do you mind if I fix the style also?

matAtWork commented 7 years ago

Is the fix for v2 or v3? I'm loathe to make many structural changes to v2, simply because I know some people have referenced .js files in nodent directly, but I'm open to change this in v3

matAtWork commented 7 years ago

As for code style, it's a bit of a mess. Occasionally I run the files through nodent with --pretty to make them consistent, but it's not a big thing for me. Lint it if you want, if I don't like it, I may edit it a bit

SimonDegraeve commented 7 years ago

Changes are only made in fast-async, not nodent.

matAtWork commented 7 years ago

Oh, sure - file the PR. I probably won't publish fast-async until I have the v3 issues sorted out, just so I can ensure no nasty co-dependencies show up