xdmp:spawn-function( $function as function() as item()*, [$options as (element()|map:map)?] ) as item()*
Place the specified function value on the task queue for evaluation.
Parameters | |
---|---|
function | A zero arity function value to execute. |
options |
The options node. The default value is (). The node must be in the
xdmp:eval namespace. For detailed options information, see
xdmp:spawn .
|
http://marklogic.com/xdmp/privileges/xdmp-spawn
The xdmp:spawn-function
function places the specified
function value in the task queue to be processed. The function will be
executed when the task server has the available resources to process it.
The tasks are processed in the order in which they are added to the
queue.
Once xdmp:spawn-function
is called, it cannot be rolled
back, even if the transaction from which it is called does not complete.
Therefore, use care calling xdmp:spawn-function
from an update
transaction. Once a module is spawned, its evaluation is asynchronous
of the transaction in which xdmp:spawn-function
was called.
Consequently, if you call xdmp:spawn-function
from a module,
and if the module ends up retrying (for example, if a deadlock is detected),
then the entire module is re-evaluated and the xdmp:spawn-function
call is therefore called again. For details on how transactions work in MarkLogic
Server, see "Understanding Transactions in MarkLogic Server" in the
Application Developer's Guide.
let $message := "Hi!" return xdmp:spawn-function(function() { xdmp:sleep(1000), xdmp:log($message) }) => Puts the inline function in the task server queue.
for $x in (1 to 10) return xdmp:spawn-function(function() {xdmp:document-insert( fn:concat("/doc", $x, ".xml"), <foo>{$x * 2}</foo>)}) (: This example uses auto commit (by default) for implicit commit. If you use <commit>explicit</commit>, then you must put an explicit xdmp:commit() in your function as it is run as a multi-statement transaction, and will rollback without an explicit xdmp:commit(). :) (: spawns functions to create the specified documents on the task server :)