Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions doc/cqueues.tex
Original file line number Diff line number Diff line change
Expand Up @@ -1295,6 +1295,10 @@ \subsubsection{\fn{signal[]}}

Returns a new promise object. $f$ is an optional function to run asynchronously, to which any subsequent arguments are passed. $f$ is called using \fn{pcall}, and the return values of \fn{pcall} are passed directly to \fn{promise:set}.

\subsubsection[\fn{promise.interpose}]{\fn{promise.interpose(name, function)}}

Add or interpose a promise class method. Returns the previous method, if any.

\subsubsection[\fn{promise:status}]{\fn{promise:status()}}

Returns ``pending'' if the promise is yet unresolved, ``fulfilled'' if the promise has been resolved (\fn{promise:get} will return the values), or ``rejected'' if the promise failed (\fn{promise:get} will throw an error).
Expand Down
6 changes: 6 additions & 0 deletions src/promise.lua
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,12 @@ local loader = function(loader, ...)
return (mt == promise and "promise") or nil
end -- promise.type

function promise.interpose(method, newfunc)
local oldfunc = promise[method]
promise[method] = newfunc
return oldfunc
end

function promise:set(ok, ...)
assert3(self.state == "pending", "attempt to set value of resolved promise")

Expand Down