Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Document how to promisify with bluebird #293

Open
fiducioso-dan opened this issue Nov 5, 2015 · 3 comments
Open

Document how to promisify with bluebird #293

fiducioso-dan opened this issue Nov 5, 2015 · 3 comments

Comments

@fiducioso-dan
Copy link

This library looks really nice and I was going to use it for a small project, but I can't figure out how to promisify it with bluebird. If you put a little code snippet in the readme showing how it would make the library more usable.

@nullivex
Copy link
Contributor

Here is the wrapper I use that provides a promisified library.

'use strict';
var P = require('bluebird')
var cradle = require('cradle')

var CouchSchema = require('./CouchSchema')

var config = require('../config')

//make some promises
P.promisifyAll(cradle)

//setup our client
var client = new (cradle.Connection)(
  config.couchdb.host,
  config.couchdb.port,
  config.couchdb.options
)

//make some promises
P.promisifyAll(client)


/**
 * Setup the DB access
 * @type {object}
 */
client.db = P.promisifyAll(client.database(config.couchdb.database))


/**
 * Add schema to helper
 * @type {CouchShema}
 */
client.schema = new CouchSchema(config.couchdb.prefix)


/**
 * Export client
 * @return {object} client
 */
module.exports = client

@kristianmandrup
Copy link

Please provide this kind of wrapper as part of Cradle. "It's the current year!"

@ForsakenHarmony
Copy link

honestly callbacks should be removed completely (except for events), bad for readability, bad for error handling (especially when you try to promisify it, because bluebird is a mess when it comes to errors)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants