summaryrefslogtreecommitdiffstats
path: root/modules/daf
diff options
context:
space:
mode:
authorMarek Vavruša <mvavrusa@cloudflare.com>2017-12-06 01:52:40 +0100
committerMarek Vavruša <marek@vavrusa.com>2018-01-08 21:40:13 +0100
commit8fa95978fb11e86ad40d4124c2485548243f81b7 (patch)
treea333a3c56ece82e3fef340b4d12aa7f8100706ea /modules/daf
parentRevert "kres: added support for NULL type" (diff)
downloadknot-resolver-8fa95978fb11e86ad40d4124c2485548243f81b7.tar.xz
knot-resolver-8fa95978fb11e86ad40d4124c2485548243f81b7.zip
Implement worker coroutines for asynchronous background processing
This implements worker coroutines in Lua to perform non-blocking I/O and do many things concurrently. For example a file watcher can be now implemented as: ``` local watcher = notify.opendir('/etc') watcher:add('hosts') -- Watch changes to /etc/hosts worker.coroutine(function () for flags, name in watcher:changes() do for flag in notify.flags(flags) do print(name, notify[flag]) end end end) ``` In order to make this work, the runtime uses the cqueues library which can run coroutines concurrently, and return a file descriptor to poll on if it's blocked. The worker takes that file descriptor and calls `event.socket(pollfd, resume_callback)` so that libuv can wake up the worker when its ready again. The cqueues library is still optional, but if it's not present following stuff won't work: * worker.coroutine() * worker.sleep()
Diffstat (limited to 'modules/daf')
-rw-r--r--modules/daf/daf.lua3
1 files changed, 1 insertions, 2 deletions
diff --git a/modules/daf/daf.lua b/modules/daf/daf.lua
index 2ddbe032..28b6342b 100644
--- a/modules/daf/daf.lua
+++ b/modules/daf/daf.lua
@@ -296,7 +296,6 @@ end
-- @function Publish DAF statistics
local function publish(_, ws)
- local cqueues = require('cqueues')
local ok, last = true, nil
while ok do
-- Check if we have new rule matches
@@ -318,7 +317,7 @@ local function publish(_, ws)
else
ok = ws:send_ping()
end
- cqueues.sleep(1)
+ worker.sleep(1)
end
end