0

I can dynamically create a function via:

new Function(['param1', 'param2'], someRotine);

However, how would I go about creating one that's async?

I tried

new AsyncFunction(['param1', 'param2'], someRotine);

but I am getting:

AsyncFunction is not defined

I am on node v14.17.0.

1
  • eval('async function() {'+code+'}') (or the same with new Function, if you care about scope) would also work Commented Jul 7, 2021 at 16:16

1 Answer 1

1

From the MDN documentation for AsyncFunction:

Note that AsyncFunction is not a global object. It can be obtained with the following code:

Object.getPrototypeOf(async function(){}).constructor
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.