Software /
code /
prosody
Comparison
util/async.lua @ 5790:959163e4d631
util.async: Make functions local
author | Matthew Wild <mwild1@gmail.com> |
---|---|
date | Mon, 12 Aug 2013 10:27:08 +0100 |
parent | 5788:3556f338caa3 |
child | 5791:2c98061b6b1e |
comparison
equal
deleted
inserted
replaced
5789:3b05a86631b9 | 5790:959163e4d631 |
---|---|
20 runner:run(); | 20 runner:run(); |
21 end | 21 end |
22 return true; | 22 return true; |
23 end | 23 end |
24 | 24 |
25 function waiter(num) | 25 local function waiter(num) |
26 local thread = coroutine.running(); | 26 local thread = coroutine.running(); |
27 if not thread then | 27 if not thread then |
28 error("Not running in an async context, see http://prosody.im/doc/developers/async"); | 28 error("Not running in an async context, see http://prosody.im/doc/developers/async"); |
29 end | 29 end |
30 num = num or 1; | 30 num = num or 1; |
52 assert(coroutine.resume(thread, self)); -- Start it up, it will return instantly to wait for the first input | 52 assert(coroutine.resume(thread, self)); -- Start it up, it will return instantly to wait for the first input |
53 return thread; | 53 return thread; |
54 end | 54 end |
55 | 55 |
56 local empty_watchers = {}; | 56 local empty_watchers = {}; |
57 function runner(func, watchers, data) | 57 local function runner(func, watchers, data) |
58 return setmetatable({ func = func, thread = false, state = "ready", notified_state = "ready", | 58 return setmetatable({ func = func, thread = false, state = "ready", notified_state = "ready", |
59 queue = {}, watchers = watchers or empty_watchers, data = data } | 59 queue = {}, watchers = watchers or empty_watchers, data = data } |
60 , runner_mt); | 60 , runner_mt); |
61 end | 61 end |
62 | 62 |