Hi,
Interesting, I never really thought of this before. I thought if
we don't want callbacks and want sequential calls, we could simply
block there.
For example, we could also do this:
client.put('chat-messages/1', {text: 'Tom left the room'}).tap{}
client.delete('user-rooms/1/2').tap{}
client.delete('rooms/1/users/1').tap{}
Here `tap{}` would force the request to be done, effectively making
those 3 calls sequential. But we probably don't really want to block
here? Then maybe a combination of them:
client.put('chat-messages/1', {text: 'Tom left the room'}) do
client.delete('user-rooms/1/2').tap{}
client.delete('rooms/1/users/1').tap{}
end
Does this make sense? This way, the first request is not blocking,
but the rests which would be called in another thread would be blocking.
At least they are not blocking the main thread. This would somehow
work like your example of using `then`, with slightly different API.
Actually, there's `then` method but it's not working like that,
and the only place which I am aware of and use it is from Github client:
https://github.com/godfat/rest-more/blob/rest-more-3.3.1/lib/rest-core/client/github.rb#L62-L78
I am not going to explain all the details here (unless anyone is interested),
but in short, it's for chaining promises and returning the chained promise.
To use that in this example, it would look like the original callback hell
with much more keystrokes, so it's not something we're looking for here.
The main difference from your example is, `then` is chaining on the original
promise, not the next one we'll expect here. If we chain them like your
example, the two subsequent requests would be made *concurrently*, and
that's not we're expecting here.
Please let me know if a callback with the others calling with `tap{}` making
sense to you. We could improve the API if that just looks weird, though I
don't feel if your example API would be possible to implement. The problem
is that, we don't know which requests we made in the callback. Sure we could
take the last value as the next request, but I feel it's too restricting and
could be unexpected. (suppose we make a bunch of requests in the first
callback, what should happen?)