File: queue-work.lua

package info (click to toggle)
lua-luv 1.51.0-1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,464 kB
  • sloc: ansic: 6,996; makefile: 74; sh: 33
file content (18 lines) | stat: -rw-r--r-- 428 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
local uv = require('luv')

local ctx = uv.new_work(
    function(n) --work,in threadpool
        local uv = require('luv')
        local t = uv.thread_self()
        uv.sleep(100)
        return n*n,n
    end,
    function(r,n) print(string.format('%d => %d',n,r)) end    --after work, in loop thread
)
uv.queue_work(ctx,2)
uv.queue_work(ctx,4)
uv.queue_work(ctx,6)
uv.queue_work(ctx,8)
uv.queue_work(ctx,10)

uv.run('default')