Skip to content

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

@igrayson

Description

@igrayson

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions