https://github.com/cloudwu/ltask
https://github.com/cloudwu/ltask
Last synced: 3 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/cloudwu/ltask
- Owner: cloudwu
- Created: 2021-01-22T12:33:16.000Z (almost 5 years ago)
- Default Branch: master
- Last Pushed: 2025-02-27T09:34:25.000Z (11 months ago)
- Last Synced: 2025-04-08T18:18:16.593Z (9 months ago)
- Language: C
- Size: 421 KB
- Stars: 289
- Watchers: 20
- Forks: 51
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- my-awesome-lua - ltask - lua multi task library, use n os thread for m lua states. (Resources / Multitasking)
README
ltask: Yet another lua task library
============================
ltask is inspired by skynet (https://github.com/cloudwu/skynet) , but it's a library rather than a framework.
It implement an n:m scheduler , so that you can run M lua VMs on N OS threads.
Each lua service (an indepentent lua VM) works in request/response mode, they use message channels to inter-communicate.
`root` is a special service that can spawn new services. For example,
```lua
-- user
local ltask = require "ltask"
local S = {}
print "User Start"
function S.ping(...)
ltask.timeout(10, function() print(1) end)
ltask.timeout(20, function() print(2) end)
ltask.timeout(30, function() print(3) end)
ltask.sleep(40) -- sleep 0.4 sec
-- response
return "PING", ...
end
return S
```
```lua
-- root
local function boot()
print "Root Start"
print(os.date("%c", (ltask.now())))
local addr = S.spawn("user", "Hello") -- spawn a new service `user`
print(ltask.call(addr, "ping", "PONG")) -- request "ping" message
end
boot()
```
Test
====
```
lua test.lua
```