untitled notebook

node v6.14.1
version: 1.0.0
endpointsharetweet
const { Promise, coroutine } = require('bluebird'); function Transaction() { this.payload = ''; } Transaction.prototype = { wrap: function () { return '<XML>' + this.payload + '</XML>'; }, addRequest: function (str) { this.payload += str return this; }, send: coroutine(function* () { const req = this.wrap(this.payload) const res = yield talkToCocc(req); return { sentPayload: req, response: res } }) } function talkToCocc (payload) { return Promise.resolve(200); } const trans = new Transaction() trans .addRequest('foo') // also tried .then(val => val) .addRequest('bar') .send() .then(res => { console.log(res); })
Loading…

no comments

    sign in to comment