Skip to content

Instantly share code, notes, and snippets.

@skrat
Created February 13, 2014 10:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save skrat/8972924 to your computer and use it in GitHub Desktop.
Save skrat/8972924 to your computer and use it in GitHub Desktop.
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