Skip to content

cloudwu/ltask

master
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Code

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
 
 
src
 
 
 
 
 
 
 
 
 
 
 
 
 
 

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. You can have a look to main.lua , it launchs an exclusive thread for timer messages and some work threads to serve some lua services.

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,

-- 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
-- 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 main.lua examples/timer/config

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published