• Marek Vavruša's avatar
    Implement worker coroutines for asynchronous background processing · 8fa95978
    Marek Vavruša authored
    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()
    8fa95978
Name
Last commit
Last update
..
README.rst Loading commit data...
daf.js Loading commit data...
daf.lua Loading commit data...
daf.mk Loading commit data...