Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[node8] Support for container.build(async () => ..) #90

Closed
igrayson opened this issue May 18, 2018 · 4 comments
Closed

[node8] Support for container.build(async () => ..) #90

igrayson opened this issue May 18, 2018 · 4 comments
Labels

Comments

@igrayson
Copy link

igrayson commented May 18, 2018

It looks like container.build() doesn't do the expected thing for (native) async functions, using Node 8.

Repro:

$ nvm install v8.0.0
$ npm install awilix@3.0.7
$ echo "
const { createContainer, InjectionMode, asValue } = require('awilix');

const container = createContainer({ injectionMode: InjectionMode.CLASSIC });

const createMyFunc = async ({ ping }) => ({
  pong: () => ping
})

container.register({
  ping: asValue('pong')
})

const myFunc = container.build(createMyFunc)
"|node

Expected result: no error thrown.

Actual result:

/private/tmp/node_modules/awilix/lib/container.js:276
            throw err;
            ^

AwilixResolutionError: Could not resolve 'async'.

Resolution path: async
    at resolve (/private/tmp/node_modules/awilix/lib/container.js:223:23)
    at dependencies.map.p (/private/tmp/node_modules/awilix/lib/resolvers.js:298:52)
    at Array.map (native)
    at Object.resolve (/private/tmp/node_modules/awilix/lib/resolvers.js:298:43)
    at Object.build (/private/tmp/node_modules/awilix/lib/container.js:298:25)
    at [stdin]:13:26
    at ContextifyScript.Script.runInThisContext (vm.js:44:33)
    at Object.runInThisContext (vm.js:116:38)
    at Object.<anonymous> ([stdin]-wrapper:6:22)
    at Module._compile (module.js:569:30)

I looked at the internals briefly, and it looks like https://github.com/jeffijoe/awilix/blob/master/src/param-parser.ts needs to be updated to handle toString()'d async functions.

@igrayson igrayson changed the title Support for container.build(async () => ..) [node8] Support for container.build(async () => ..) May 18, 2018
@jeffijoe
Copy link
Owner

Good catch! Awilix does not include anything related to async, so I’m not entirely sure what you’re doing, but I’ll definitely make sure this works as expected. I’m away from my dev machine until tuesday though, so it won’t be earlier than that. 😀

@igrayson
Copy link
Author

For us, there was no good reason for that function to be async (and it no longer is)!

@jeffijoe
Copy link
Owner

Regardless, it should work, so I’ll make sure it does. 😄

@jeffijoe jeffijoe added the bug label May 21, 2018
jeffijoe added a commit that referenced this issue May 21, 2018
Add parser support for async and generator funcs, fixes #90 

Closes #90
@jeffijoe
Copy link
Owner

@igrayson the fix has been published as v3.0.8, thanks for reporting!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants