-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwait_posix.lua
More file actions
44 lines (33 loc) · 1.33 KB
/
Copy pathwait_posix.lua
File metadata and controls
44 lines (33 loc) · 1.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
-- Module using effects to wait for I/O on POSIX platforms
-- Disallow setting global variables in the implementation of this module:
_ENV = setmetatable({}, {
__index = _G,
__newindex = function() error("cannot set global variable", 2) end,
})
-- Table containing all public items of this module:
local _M = {}
local effect = require "neumond.effect"
local wait = require "neumond.wait"
local wait_select = wait.select
-- wait_posix.select is an alias for wait.select:
_M.select = wait_select
-- Effect deregister_fd(fd) deregisters file descriptor fd, which should be
-- done before closing a file descriptor that is currently waited on:
_M.deregister_fd = effect.new("wait_posix.deregister_fd")
-- wait_fd_read(fd) waits until file descriptor fd is ready for reading:
function _M.wait_fd_read(fd)
return wait_select("fd_read", fd)
end
-- wait_fd_write(fd) waits until file descriptor fd is ready for writing:
function _M.wait_fd_write(fd)
return wait_select("fd_write", fd)
end
-- wait_pid(pid) waits until the process with the given pid has exited:
function _M.wait_pid(pid)
return wait_select("pid", pid)
end
-- Effect catch_signal(sig) starts listening for signal sig and returns a
-- callable handle which, upon calling, waits until a signal has been
-- delivered:
_M.catch_signal = effect.new("wait_posix.catch_signal")
return _M