levent

lua concurrency library based on libev, similar with gevent

191
61
C

levent

levent is a lua concurrency networking library inspired by gevent.

Features include:

  • Fast event loop based on libev.
  • Simple and clean socket library
  • Cooperative dns client by pure lua
  • Similar api and components with gevent but with much more simpler implementation and better performance.

levent is licensed under MIT license.

get levent

Install lua 5.3 or newer(for lua5.2 and older, see branch lua5.2).

Clone the repository.

Read test case and examples.

Post feedback and issues on the bug tracker,

build

Need cmake 2.8 or newer.

Modify cmake.config properly and then run:

cmake .
make

ways to build on windows, ref to blog

code example

levent’s api is clean, to request http concurrently is as simple as below:

lua <<SCRIPT
local levent = require "levent.levent"
local http   = require "levent.http"

local urls = {
    "http://www.google.com",
    "http://yahoo.com",
    "http://example.com",
    "http://qq.com",
}

function request(url)
    local response, err = http.get(url)
    if not response then
        print(url, "error:", err)
    else
        print(url, response:get_code())
    end
end

function main()
    for _, url in ipairs(urls) do
        levent.spawn(request, url)
    end
end

levent.start(main)
SCRIPT

running tests

there are some tests and examples under tests and examples to illustrate how to use levent, you can run tests and examples from root folder of levent as below.

lua tests/test_socket.lua
lua examples/dns_mass_resolve.lua

documents

coming soon~~

licence

The MIT License (MIT)
Copyright © 2014 xjdrew