#
cp.rx.go.Statement
A Statement
is defined to enable processing of asynchronous resolvable
values such
as cp.rx.Observable values.
To define a new Statement
, you call the
#
Definine a new Statement
To define a new Statement
implementation, we use the
Statements may have an onInit
, and must have an onObservable
provided,
and then the define
method must be called.
For example, the First statement is defined like so:
local First = Statement.named("First")
:onInit(function(context, resolvable)
assert(resolvable ~= nil, "The First `resolveable` may not be `nil`.")
context.resolvable = resolvable
end)
:onObservable(function(context)
return toObservable(context.resolvable):first()
end)
:define()
Once you've defined a statement, you then execute it by calling the statement directly, passing in any parameters.
For example:
local First = require("cp.rx.go").First
First(Observable.of(1, 2, 3))
:Now(
function(value) print("Received: "..tostring(value)) end,
function(message) print("Error: "..tostring(message)) end,
function() print("Completed") end
)
This will output:
Received: 1
Completed
The Observable
as passed to the onInit
function handler as the second parameter.
context
is always the first parameter, followed by any values passed to the constructor call.
The onObservable
function handler is called once the statement is actually executing, typically
by calling the
It is recommended that any conversion of input parameters are converted to
Observable
s as late as possible, typically in theonObservable
function handler. Otherwise, input values may get resolved before the user intends.
#
Submodules
#
API Overview
Functions - API calls offered directly by the extension
defaultObserverFactory is toObservable toObservables
Constructors - API calls which return an object, typically one that offers API methods
named
Methods - API calls which can only be made on an object returned by a constructor
After Catch Debug Finally fullName Label name Now ThenDelay ThenYield TimeoutAfter toObservable