Stored closures which can potentially make changes to ThingsDB are called
closures with side effects and must be wrapped with the wse(..)
function.
This allows ThingsDB before running the query to make an event.
You should use wse
only when required, otherwise this would lead to unnecessary events.
This function generates an event.
wse(statement)
Argument | Type | Description |
---|---|---|
statement | any | Statement or block to wrap. |
Return value of the given statement.
This code shows an example usage for wse():
// Suppose we have a closure with side-effects
.take_license = || .licenses -= 1;
// And we have some initial licenses
.licenses = 99;
wse({
// without wse() this would raise an error
.take_license();
});
// Return the number of licenses left
.licenses;
Return value in JSON format
98