lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


Hello Community,

I'm pleased to announce luajls 0.7 [1], the noticeable changes are:
- an effort to clear and simplify the APIs,
- new features such as Async/Await for Promise [2], Abstract Syntax Tree module to parse and generate Lua code [3], - new concepts such as *Exception* to group the error message and its associated stack [4], *Codec* to encode/decode a string [5].

The async/await pattern allows asynchronous/non-blocking functions to be written in a traditional synchronous/blocking style, see example below [6].

All feedbacks are welcome.

Thank you and have a good day,
Samuel

[1] https://github.com/javalikescript/luajls
[2] https://javalikescript.github.io/luajls/modules/jls.lang.Promise.html#Promise.async
[3] https://javalikescript.github.io/luajls/modules/jls.util.ast.html
[4] https://javalikescript.github.io/luajls/modules/jls.lang.Exception.html
[5] https://javalikescript.github.io/luajls/modules/jls.util.Codec.html
[6] Async/Await example:
local event = require('jls.lang.event')
local Promise = require('jls.lang.Promise')

local function incrementLater(n, millis) -- asynchronous function that return a promise that will resolve after a timeout
  return Promise:new(function(resolve)
    event:setTimeout(resolve, millis or 0, n + 1)
  end)
end

Promise.async(function(await) -- async itself is asynchronous and return a promise   local n = await(incrementLater(1, 1000)) -- await will block then return 2 after 1 second
  print(await(incrementLater(n, 1000))) -- prints 3 after another second
end):catch(error)

event:loop()