From 7766e59b6e31c024fe0604a18ddc6fac2dfc5b6c Mon Sep 17 00:00:00 2001 From: Robin Murphy Date: Tue, 3 Jan 2017 12:02:31 +0000 Subject: [PATCH] Feature: Expose Client for simpler promisification * Adds documentation on promisification to readme --- README.md | 16 ++++++++++++++++ index.js | 2 ++ 2 files changed, 18 insertions(+) diff --git a/README.md b/README.md index 54360da..a63608e 100644 --- a/README.md +++ b/README.md @@ -25,6 +25,7 @@ npm install --save flashheart * [StatsD integration](#stats) * [Retries](#retries) * [Circuit breaker](#circuit-breaker) +* [Promises](#promises) ## Usage @@ -217,6 +218,21 @@ const client = require('flashheart').createClient({ }); ``` +### Promises + +Flashheart uses callbacks, but we expose the `Client` constructor to make it easy to [promisify](http://bluebirdjs.com/docs/api/promisification.html) the entire library: + +```js +const Promise = require('bluebird'); +const Client = require('flashheart').Client; +const client = require('flashheart').createClient(); + +Promise.promisifyAll(Client.prototype); + +client.getAsync('http://httpstat.us/200') + .then((body) => console.log(body)); +``` + ## API #### Callback return values diff --git a/index.js b/index.js index cd25eda..95b5bdb 100644 --- a/index.js +++ b/index.js @@ -13,3 +13,5 @@ module.exports.createClient = function (opts) { return client; }; + +module.exports.Client = Client;