Skip to content

Commit 4d62db5

Browse files
authored
Add popen_handle:wait() parameter and new errors (#5099)
* Add popen_handle:wait() parameter and new errors Since version 3.2.0 the popen_handle:wait() method has one more parameter and may raise two more errors: Param timeout Error TimedOut Error ChannelIsClosed * Add popen_handle:wait() parameter and new errors Fixes previous commit syntax errors * Add popen_handle:wait() parameter and new errors Fixes previous commit syntax errors
1 parent 7b6e434 commit 4d62db5

File tree

1 file changed

+19
-4
lines changed

1 file changed

+19
-4
lines changed

doc/reference/reference_lua/popen.rst

+19-4
Original file line numberDiff line numberDiff line change
@@ -745,19 +745,34 @@ Below is a list of all ``popen`` functions and handle methods.
745745
:param handle ph: handle of a child process created with
746746
:ref:`popen.new() <popen-new>` or
747747
:ref:`popen.shell() <popen-shell>`
748+
:param number timeout: since version 3.2.0. The parameter defines the period in seconds for the method to wait for a resolution.
748749
:return: (if success) formatted result
749750
:rtype: res
750751

751-
Possible raised errors are:
752+
Possible raised errors:
752753

753-
* IllegalParams: an incorrect handle parameter
754-
* IllegalParams: called on a closed handle
755-
* FiberIsCancelled: cancelled by an outside code
754+
* ``IllegalParams``: an incorrect handle parameter
755+
* ``IllegalParams``: called on a closed handle
756+
* ``FiberIsCancelled``: cancelled by an outside code
757+
* ``TimedOut``: since version 3.2.0. The error means that the method has not reached the positive result but has reached the defined **timeout**.
758+
* ``ChannelIsClosed``: since version 3.2.0. The error is returned when the target popen handle is closed from another fiber.
756759

757760
The formatted result is a process status table (the same as the
758761
``status`` component of the table returned by
759762
:ref:`popen_handle:info() <popen-info>`).
760763

764+
**Timeout parameter example**
765+
766+
.. code-block:: lua
767+
768+
local ph = popen.new(<...>)
769+
local res, err = ph:wait({timeout = 1})
770+
if res == nil then
771+
-- Timeout is reached.
772+
assert(err.type == 'TimedOut')
773+
<...>
774+
end
775+
761776
.. _popen-close:
762777

763778
.. method:: close()

0 commit comments

Comments
 (0)