Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 20 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ var fs = require("fs");
var mime = require("mime");
var Util = require("./util");
var Url = require("url");
var Promise = require("./promise");

/** section: github
* class Client
Expand Down Expand Up @@ -178,6 +179,7 @@ var Client = module.exports = function(config) {
config.headers = config.headers || {};
this.config = config;
this.debug = Util.isTrue(config.debug);
this.Promise = config.Promise || config.promise || Promise;

this.version = config.version;
var cls = require("./api/v" + this.version);
Expand Down Expand Up @@ -362,8 +364,25 @@ var Client = module.exports = function(config) {
// on error, there's no need to continue.
return;
}
if (!callback){
if (self.Promise) {
return new self.Promise(function(resolve,reject){
var cb = function(err, obj){
if (err){
reject(err);
} else {
resolve(obj);
}
};
api[section][funcName].call(api, msg, block, cb);
});
} else {
throw new Error('neither a callback or global promise implementation was provided');
}
} else {
api[section][funcName].call(api, msg, block, callback);
}

api[section][funcName].call(api, msg, block, callback);
};
}
else {
Expand Down
17 changes: 17 additions & 0 deletions promise.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
"use strict";

var Promise = global.Promise || null;

if (isFunction(Promise)) {
new Promise(function(resolver) {
if (!isFunction(resolver)) {
Promise = null;
}
});
}

module.exports = Promise;

function isFunction(x) {
return typeof x === "function";
}