Created
February 13, 2014 10:32
-
-
Save skrat/8972924 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var jayson = require(__dirname + '/../..'); | |
var wrap_jayson = function(client) { | |
return { | |
request: function(name, args) { | |
return new Promise(function(resolve, reject) { | |
client.request(name, args, function(err, error, response) { | |
if (err) return reject(err); | |
resolve(response); | |
}) | |
}); | |
} | |
} | |
}; | |
// create a client | |
var client = wrap_jayson(jayson.client.http({ | |
port: 3000, | |
hostname: 'localhost' | |
})); | |
// invoke "add" | |
client.request('add', [1, 1]).then(function(response) { | |
console.log(response); // 2! | |
}).catch(function(err) { | |
console.error(err); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment