An API chain is TECHNICALLY a complete monad wherein one request/response is made and the output is sent back. The chain is a dynamic stateless chain of apis sent as a a monad processed on the backend through a push/pull mechanism (like loopback or a HandlerInterceptor). Thus requests and responses are minimized and thus the term 'chain' is derived.
Making constant request/response calls over and over and over does not constitute an api chain. See docs on the API Chaining pattern (https://www.google.com/webhp?sourceid=chrome-instant&ion=1&espv=2&ie=UTF-8#q=api%20chaining) On Tuesday, September 23, 2014 at 5:34:06 PM UTC-7, Alex Kocharin wrote: > > > There seem to be a conflict between chaining api and promise-based api. > Both of them use return value, but chaining api returns `this`, and > promise-based one returns promise. > > Is it possible to use both at the same time? > > Here is some abstract example. Suppose we have a class: > > ```js > function Message(text) { > var self = Object.create(Message.prototype) > self.text = text > return self > } > > Message.prototype.send = function(server, callback) { > servers[server].doStuff(callback) > return this > } > ``` > > Which can be used this way: > > ```js > Message("text") > .send("server1", function() { console.log("message sent to server 1") > } ) > .send("server2", function() { console.log("message sent to server 2") > } ) > ``` > > Some users want to use promises. Ideally, it'll look like that: > > ```js > Message("text") > .send("server1") > .then( function() { console.log("message sent to server 1") } ) > .send("server2") > .then( function() { console.log("message sent to server 2") } ) > ``` > > I'm sure it's possible with prototype injection into promise, but it > surely sounds weird. Is there a better way? > > -- > // alex > -- Job board: http://jobs.nodejs.org/ New group rules: https://gist.github.com/othiym23/9886289#file-moderation-policy-md Old group rules: https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines --- You received this message because you are subscribed to the Google Groups "nodejs" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/nodejs/aa029fa4-845e-4917-a195-3fec29a697a7%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
