Skip to content

sclu1034/lgi-async-extra

Repository files navigation

lgi-async-extra

License Build Status (GitHub Actions) LuaRocks Package

An asynchronous high(er)-level API wrapper for LGI.

Quick Start

Install lgi and lgi-async-extra, and optionally async.lua, via LuaRocks:

luarocks install lgi
luarocks install lgi-async-extra
luarocks install async.lua
local lgi = require("lgi")
local async = require("async")
local File = require("lgi-async-extra.file")

local path = string.format("%s/foo.txt", lgi.GLib.get_tmp_dir())
local f = File.new_for_path(path)

async.waterfall({
    function(cb)
        -- By default, writing replaces any existing content
        f:write("hello", cb)
    end,
    function(cb)
        -- But we can also append to the file
        f:write("world", "append", cb)
    end,
    function(cb)
        f:read_string(cb)
    end,
}, function(err, data)
    print(err)
    print(data)
end)

Make sure to have a GLib Main Loop running.