News for hackers. Stuff that matters.
Re:JavaScript's world domination by ufo on Tuesday March 24, 2015 @07:25PM (#9260273)
One nice thing about Lua coroutines is that they are "stackful". You don't need to chain "yields" all the way up the call stack (like Python's "yield from") so its possible to create functions that work with both sync and async callbacks.

    function mapList(xs, f)
        local ys = {}
        for i=1,#xs do
            ys[i] = f(xs[i])
        end
        return ys
    end

    mapList({10, 20, 30}, function(x)
        return db.fetch(x)
    end)
In JS you can't use async functions inside of Array.prototype.map. You need to use a separate async-aware method from your favorite async library instead.

There are no comments on this comment yet.