AsyncCall Class Referenceabstract

#include <Pt/Lua/AsyncCall.h>

Asynchronous native call from Lua. More...

Inherited by BasicAsyncCall< void >, BasicAsyncCall< R >, and BasicAsyncCall< void >.

Public Member Functions

 AsyncCall ()
 Creates an idle asynchronous call.
virtual ~AsyncCall ()
 Destroys the call.
void bind (Pt::Reflex::TypeManager &tm)
 Binds the result type from tm.
Pt::Reflex::Type * rtype () const
 Returns the Reflex result type, or a null pointer before bind.
void beginCall (Pt::System::EventLoop &loop)
 Starts the call on loop.
Pt::Any getResult ()
 Returns the result after the call has finished.
Pt::Signalfinished ()
 Signal emitted when the call is ready or has failed.
void cancel ()
 Cancels the call.
bool hasError () const
 Returns true when the call stored an error.
const std::string & errorMessage () const
 Returns the stored error text.

Protected Member Functions

void setReady ()
 Emits finished() to mark the call ready.
void setError (const std::string &msg)
 Stores msg as the error of this call.

Detailed Description

AsyncCall is native work that Lua starts and that finishes later on an EventLoop. A reflected function or method whose return type is AsyncCall* returns a heap instance; the Script takes ownership, binds it, starts it, and resumes when finished() is emitted.

Subclass BasicAsyncCall rather than this type. The script calls bind() with the context's type manager so rtype() is known, then beginAdvance() on the loop, which reaches onBeginCall(). When the work is done, setReady() emits finished(). setError() records a failure instead. The script then calls getResult() and pushes it to Lua, or becomes ScriptError. cancel() reaches onCancel().