summaryrefslogtreecommitdiffstats
path: root/player/lua
diff options
context:
space:
mode:
authorCogentRedTester <cogent.redtester@outlook.com>2022-06-22 21:06:09 +0930
committerAvi Halachmi (:avih) <avihpit@yahoo.com>2022-06-22 14:44:12 +0300
commit099ae8671732a333216a622cba7751f08deff9af (patch)
treea75d91f44d9abf9b22658e7ec2fe66d844b83182 /player/lua
parent24f4582b6f7f57f566418551f9252b8578d2b602 (diff)
downloadmpv-099ae8671732a333216a622cba7751f08deff9af.tar.bz2
mpv-099ae8671732a333216a622cba7751f08deff9af.tar.xz
lua: command_native_async: always callback a-sync
Previously if the raw command_native_async returned an error then the callback function was run directly. This meant that script writers potentially had to account for both synchronous and asynchronous logic in the callback, which can happen even with seemingly 'safe' commands if the mpv event queue is full. This was at odds with the Javascript implementation of the function, which always runs the callback asynchronously. Now the mp.add_timeout function is used to run the callback asynchronously on error, replicating the Javascript implementation. This provides consistency for developers in how the callback is handled in Lua, and increases consistency between the Lua and Javascript APIs.
Diffstat (limited to 'player/lua')
-rw-r--r--player/lua/defaults.lua2
1 files changed, 1 insertions, 1 deletions
diff --git a/player/lua/defaults.lua b/player/lua/defaults.lua
index 0643c0b1d9..dcbb4e0f62 100644
--- a/player/lua/defaults.lua
+++ b/player/lua/defaults.lua
@@ -617,7 +617,7 @@ function mp.command_native_async(node, cb)
async_next_id = async_next_id + 1
local res, err = mp.raw_command_native_async(id, node)
if not res then
- cb(false, nil, err)
+ mp.add_timeout(0, function() cb(false, nil, err) end)
return res, err
end
local t = {cb = cb, id = id}