Stats

 Latest version : 0.0.2

 Last updated on 2017-06-11T14:16:53.617Z

 Keywords : template, engine, ejs, async

 Downloads :

  • 17 in Last Month

 Links :

 Examples

¯\_(ツ)_/¯
No examples found for this package

 Readme

[https://github.com/mde/ejs/issues/262](the async/await ejs.)

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){
  // ....
  // ....
}

 Comments