> <i>Promises/A has been ported to Ruby, with basically the same API…</i><p>This is, to me, the core of the problem.<p>> <i>The Promises/A spec from CommonJS defines Promise.then as taking three (optional) callbacks: fulfilledHandler, errorHandler, and progressHandler. The code above is passing two of them at once.</i><p>Shoehorning things from different realms (e.g desperately trying to write JS in Ruby or vice-versa) is not a good idea.<p>Instead of either:<p><pre><code> db.select_one(sql, thingid)
.then((proc {|rowset| rowset[0]['foo'}), (proc {|err| log_error(err)}))
</code></pre>
or:<p><pre><code> db.select_one(sql, thingid)
.then {|rowset| rowset[0]['foo'}
.then(nil) {|err| log_error(err)}
</code></pre>
Why not do:<p><pre><code> db.select_one(sql, thingid)
.then {|rowset| rowset[0]['foo'}
.else {|err| log_error(err)}
.each {|whatever| the_progress(callback_is)}
</code></pre>
Also, <i>method(:log_error)</i> will happily turn the method into a proc.<p>This last case is actually extremely important. Contrary to what the author claims, functions and methods <i>are</i> first class in Ruby. The problem is that in Ruby's grammar an identifier without parentheses is a method call if that identifier does not resolve to a variable. Therefore, you cannot refer to an existing function by its name, merely because it would resolve to a call.<p>Therefore the difference between those is <i>purely syntactic</i>:<p><pre><code> Python Ruby
foo method(:foo)
foo() foo
</code></pre>
Also, this[0] explains how <i>&:to_i</i> works, which can be leveraged with great success, should one implement the promise class in a sufficiently idiomatic way (turning the above <i>log_error</i> reference into &:log_error)<p>[0]: <a href="http://ablogaboutcode.com/2012/01/04/the-ampersand-operator-in-ruby/" rel="nofollow">http://ablogaboutcode.com/2012/01/04/the-ampersand-operator-...</a>