With minor difference from lua, as documented.
Showing the changes to player/javascript (1 of 3 files). Show all
Unified · Split
| @@ -144,8 +144,15 @@ var async_next_id = 1; · 143 unmodified lines | |||
| 144 | 144 | ||
| 145 | mp.command_native_async = function command_native_async(node, cb) { | 145 | mp.command_native_async = function command_native_async(node, cb) { |
| 146 | var id = async_next_id++; | 146 | var id = async_next_id++; |
| 147 | cb = cb || function dummy() {}; | ||
| 148 | if (!mp._command_native_async(id, node)) { | ||
| 149 | var le = mp.last_error(); | ||
| 150 | setTimeout(cb, 0, false, undefined, le); /* callback async */ | ||
| 151 | mp._set_last_error(le); | ||
| 152 | return undefined; | ||
| 153 | } | ||
| 147 | async_callbacks[id] = cb; | 154 | async_callbacks[id] = cb; |
| 148 | return mp._command_native_async(id, node); | 155 | return id; |
| 149 | } | 156 | } |
| 150 | 157 | ||
| 151 | function async_command_handler(ev) { | 158 | function async_command_handler(ev) { |
| @@ -157,6 +164,12 @@ function async_command_handler(ev) { · 5 unmodified lines | |||
| 157 | cb(true, ev.result, ""); | 164 | cb(true, ev.result, ""); |
| 158 | } | 165 | } |
| 159 | 166 | ||
| 167 | mp.abort_async_command = function abort_async_command(id) { | ||
| 168 | // cb will be invoked regardless, possibly with the abort result | ||
| 169 | if (async_callbacks[id]) | ||
| 170 | mp._abort_async_command(id); | ||
| 171 | } | ||
| 172 | |||
| 160 | /********************************************************************** | 173 | /********************************************************************** |
| 161 | * key bindings | 174 | * key bindings |
| 162 | *********************************************************************/ | 175 | *********************************************************************/ |