Skip to content

Commit f61bc7a

Browse files
committed
docs: improve async usage
1 parent 2a5f76e commit f61bc7a

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

README.md

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -58,19 +58,25 @@ ejs.__EJS__.fileLoader = function () { /* custom file loader */ }
5858

5959
### Async rendering (requires runtime support)
6060

61-
You can use async/await in ejs template by passing `{async: true}` in options:
61+
Since ejs [v2.5.8](https://github.com/mde/ejs/releases/tag/v2.5.8) added support for promise/async-await `renderFile`, you can now use this option with gulp-ejs v4.1.0.
62+
63+
You can use async/await in your ejs templates by passing `{ async: true }` in the ejs options hash:
6264

6365
```javascript
6466
const ejs = require('gulp-ejs')
6567

66-
async function blah() { /* async task */ }
68+
async function foobar() { /* async task */ }
6769

68-
gulp.src("./templates/*.ejs")
69-
.pipe(ejs({blah}, {async: true}))
70-
.pipe(gulp.dest("./dist"))
70+
gulp.src('./templates/*.ejs')
71+
.pipe(ejs({ foobar }, { async: true }))
72+
.pipe(gulp.dest('./dist'))
7173
```
7274

73-
In template, await will be used to call async functions for example: `<%= await blah() %>`
75+
Then in your templates use `await` to call async functions. Here's an example:
76+
77+
```javascript
78+
<%= await foobar() %>
79+
```
7480

7581
## API
7682

0 commit comments

Comments
 (0)