1
0
mirror of https://github.com/mpv-player/mpv synced 2025-01-12 01:49:33 +00:00

js: expose mpv_abort_async_command() (match dbe831bd)

With minor difference from lua, as documented.
This commit is contained in:
Avi Halachmi (:avih) 2019-03-12 11:35:55 +02:00
parent ad0a525f20
commit 44f8dccfb6
3 changed files with 26 additions and 3 deletions

View File

@ -96,8 +96,10 @@ Where the Lua APIs use ``nil`` to indicate error, JS APIs use ``undefined``.
``mp.command_native(table [,def])`` (LE)
``mp.command_native_async(table [,fn])`` (LE) Note: ``error`` is empty string on
success.
``id = mp.command_native_async(table [,fn])`` (LE) Notes: ``id`` is true-thy on
success, ``fn`` is called always a-sync, ``error`` is empty string on success.
``mp.abort_async_command(id)``
``mp.get_property(name [,def])`` (LE)

View File

@ -718,6 +718,13 @@ static void script__command_native_async(js_State *J, void *af)
push_status(J, mpv_command_node_async(jclient(J), id, &node));
}
// args: async-command-id
static void script__abort_async_command(js_State *J)
{
mpv_abort_async_command(jclient(J), jsL_checkuint64(J, 1));
push_success(J);
}
// args: none, result in millisec
static void script_get_time_ms(js_State *J)
{
@ -1232,6 +1239,7 @@ static const struct fn_entry main_fns[] = {
FN_ENTRY(commandv, 0),
AF_ENTRY(command_native, 2),
AF_ENTRY(_command_native_async, 2),
FN_ENTRY(_abort_async_command, 1),
FN_ENTRY(get_property_bool, 2),
FN_ENTRY(get_property_number, 2),
AF_ENTRY(get_property_native, 2),

View File

@ -144,8 +144,15 @@ var async_next_id = 1;
mp.command_native_async = function command_native_async(node, cb) {
var id = async_next_id++;
cb = cb || function dummy() {};
if (!mp._command_native_async(id, node)) {
var le = mp.last_error();
setTimeout(cb, 0, false, undefined, le); /* callback async */
mp._set_last_error(le);
return undefined;
}
async_callbacks[id] = cb;
return mp._command_native_async(id, node);
return id;
}
function async_command_handler(ev) {
@ -157,6 +164,12 @@ function async_command_handler(ev) {
cb(true, ev.result, "");
}
mp.abort_async_command = function abort_async_command(id) {
// cb will be invoked regardless, possibly with the abort result
if (async_callbacks[id])
mp._abort_async_command(id);
}
/**********************************************************************
* key bindings
*********************************************************************/