question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

support async/await

See original GitHub issue

I find the way to support ‘async/await’.

let tempate = 'Hello <%- await getName() %>';
let getName = () => {
  return new Promise( (res, rej) => {
     setTimeout(() => {
        res('John');
     }, 1000)
  })
}
html = await ejs.render(template, {getName});
// Hello John.

HOW TO ?

//  lib/ejs.js  line 523
try {
      // let fn to be async.
      eval(`fn = async function(${opts.localsName}, escapeFn, include, rethrow){${src}}`);
      // fn = new Function(opts.localsName + ', escapeFn, include, rethrow', src);
}catch(e){
  // ....
  // ....
}

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:8 (3 by maintainers)

github_iconTop GitHub Comments

8reactions
whiskascommented, Mar 3, 2018

don’t do that! keep ejs fast and simple! If you need, you have to do asyn/await wrap around ejs render call.

1reaction
RyanZimcommented, Jun 12, 2017

@mde Sometime, I think we should work on a major version of EJS adding promise support, etc. Not sure when though.

Read more comments on GitHub >

github_iconTop Results From Across the Web

async function - JavaScript - MDN Web Docs - Mozilla
Async functions can contain zero or more await expressions. Await expressions make promise-returning functions behave as though they're ...
Read more >
Async functions | Can I use... Support tables for HTML5, CSS3 ...
Async functions make it possible to treat functions returning Promise objects as if they were synchronous. Usage % of. all users, all tracked,...
Read more >
Async functions: making promises friendly - web.dev
If you use the async keyword before a function definition, you can then use await within the function. When you await a promise, ......
Read more >
Async/await - The Modern JavaScript Tutorial
The syntax: // works only inside async functions let value = await promise; The keyword await makes JavaScript wait until that promise settles ......
Read more >
Is it safe to use async/await now? [closed] - Stack Overflow
According to the release notes, Safari 10.1 added support for ECMAScript 2016 and ECMAScript 2017 in Safari for macOS and iOS, including support...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found