Skip to content

Write async function more like javascript async/await

License

Notifications You must be signed in to change notification settings

iamcco/async-await.lua

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 

Repository files navigation

async-await.lua

Write async function more like javascript async/await

await the async callback function

local aw = require('async-await')
local timer = vim.loop.new_timer()

aw.async(function ()

  local hello = aw.await(function (cb)
    timer:start(1000, 0, function ()
      cb('hello')
    end)
  end)

  local world = aw.await(function (cb)
    timer:start(1000, 0, function ()
      cb('world')
    end)
  end)

  print(hello, world)
end)

await the async function

local aw = require('async-await')
local timer = vim.loop.new_timer()

local hello_world = aw.async(function ()

  local hello = aw.await(function (cb)
    timer:start(1000, 0, function ()
      cb('hello')
    end)
  end)

  local world = aw.await(function (cb)
    timer:start(1000, 0, function ()
      cb('world')
    end)
  end)

  return hello,world
end)

aw.async(function()
    local hello, world = aw.await(hello_world)
    print(hello, world)
end)

About

Write async function more like javascript async/await

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Languages