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.

Function wse() might also be called without arguments which can be used to force ThingsDB to generate an event. This might be useful for when it is really important that a query returns a result based on a state where all previous events are processed.

You should use wse only when required, otherwise this would lead to unnecessary events.

This function generates an event.




Argument Type Description
statement any (optional) Statement or block to wrap.

Return value

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;

    // without wse() this would raise an error

// Return the number of licenses left

Return value in JSON format