Skip to content

Commit

Permalink
Merge pull request #197 from alexsomeoddpilot/master
Browse files Browse the repository at this point in the history
Adding readme info on promise API
  • Loading branch information
doowb committed May 26, 2015
2 parents 43392f5 + 3fa6832 commit 1fcecc1
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,22 @@ cons[name]('views/page.html', { user: 'tobi' }, function(err, html){
});
```

### Promises

Additionally, all templates optionally return a promise if no callback function is provided. The promise represents the eventual result of the template function which will either resolve to a string, compiled from the template, or be rejected. Promises expose a `then` method which registers callbacks to receive the promise’s eventual value and a `catch` method which the reason why the promise could not be fulfilled. Promises allow more synchronous-like code structure and solve issues like race conditions.

```js
var cons = require('consolidate');

cons.swig('views/page.html', { user: 'tobi' })
.then(function (html) {
console.log(html);
})
.catch(function (err) {
throw err;
});
```

## Caching

To enable or disable caching simply pass `{ cache: true/false }`. Engines _may_ use this option to cache things reading the file contents, compiled `Function`s etc. Engines which do _not_ support this may simply ignore it. All engines that consolidate.js implements I/O for will cache the file contents, ideal for production environments.
Expand Down

0 comments on commit 1fcecc1

Please sign in to comment.