Lua:synchronize
Jump to navigation
Jump to search
Calls the given function from the main thread.
Any additional arguments are passed to the function when it is called. The return value of the given function is returned by synchronize.
Function Parameters[edit]
| Parameter | Type | Description |
|---|---|---|
| function | Function | The function to call from the main thread. |
| ... | Any (optional) | Additional arguments that are passed to the function. |
Returns[edit]
any — The return value of the given function.
Examples[edit]
1 local result = synchronize(function()
2 return getMainForm().Caption
3 end)
4
5 print(result)
1 local function add(a, b)
2 return a + b
3 end
4
5 local result = synchronize(add, 10, 20)
6
7 print(result)
1 function ShowError(message)
2 if not inMainThread() then
3 synchronize(function()
4 self:ShowError(message)
5 end)
6 return
7 end
8 messageDialog(message, mtError, mbOK)
9 end
10
11 ShowError("Some Error!")