mirror of
https://github.com/hexedtech/codemp.git
synced 2024-12-22 21:04:53 +01:00
feat: add promise abort for lua
This commit is contained in:
parent
5e2e711b55
commit
d21969cb81
2 changed files with 31 additions and 0 deletions
24
dist/lua/annotations.lua
vendored
24
dist/lua/annotations.lua
vendored
|
@ -18,6 +18,9 @@ local NilPromise = {}
|
|||
--- block until promise is ready
|
||||
function NilPromise:await() end
|
||||
|
||||
--- cancel promise execution
|
||||
function NilPromise:abort() end
|
||||
|
||||
---@param cb fun() callback to invoke
|
||||
---invoke callback asynchronously as soon as promise is ready
|
||||
function NilPromise:and_then(cb) end
|
||||
|
@ -30,6 +33,9 @@ local StringPromise = {}
|
|||
--- @return string
|
||||
function StringPromise:await() end
|
||||
|
||||
--- cancel promise execution
|
||||
function StringPromise:abort() end
|
||||
|
||||
---@param cb fun(x: string) callback to invoke
|
||||
---invoke callback asynchronously as soon as promise is ready
|
||||
function StringPromise:and_then(cb) end
|
||||
|
@ -40,6 +46,8 @@ local StringArrayPromise = {}
|
|||
--- block until promise is ready and return value
|
||||
--- @return string[]
|
||||
function StringArrayPromise:await() end
|
||||
--- cancel promise execution
|
||||
function StringArrayPromise:abort() end
|
||||
---@param cb fun(x: string[]) callback to invoke
|
||||
---invoke callback asynchronously as soon as promise is ready
|
||||
function StringArrayPromise:and_then(cb) end
|
||||
|
@ -50,6 +58,8 @@ local ClientPromise = {}
|
|||
--- block until promise is ready and return value
|
||||
--- @return Client
|
||||
function ClientPromise:await() end
|
||||
--- cancel promise execution
|
||||
function ClientPromise:abort() end
|
||||
---@param cb fun(x: Client) callback to invoke
|
||||
---invoke callback asynchronously as soon as promise is ready
|
||||
function ClientPromise:and_then(cb) end
|
||||
|
@ -60,6 +70,8 @@ local WorkspacePromise = {}
|
|||
--- block until promise is ready and return value
|
||||
--- @return Workspace
|
||||
function WorkspacePromise:await() end
|
||||
--- cancel promise execution
|
||||
function WorkspacePromise:abort() end
|
||||
---@param cb fun(x: Workspace) callback to invoke
|
||||
---invoke callback asynchronously as soon as promise is ready
|
||||
function WorkspacePromise:and_then(cb) end
|
||||
|
@ -70,6 +82,8 @@ local WorkspaceEventPromise = {}
|
|||
--- block until promise is ready and return value
|
||||
--- @return WorkspaceEvent
|
||||
function WorkspaceEventPromise:await() end
|
||||
--- cancel promise execution
|
||||
function WorkspaceEventPromise:abort() end
|
||||
---@param cb fun(x: WorkspaceEvent) callback to invoke
|
||||
---invoke callback asynchronously as soon as promise is ready
|
||||
function WorkspaceEventPromise:and_then(cb) end
|
||||
|
@ -80,6 +94,8 @@ local BufferControllerPromise = {}
|
|||
--- block until promise is ready and return value
|
||||
--- @return BufferController
|
||||
function BufferControllerPromise:await() end
|
||||
--- cancel promise execution
|
||||
function BufferControllerPromise:abort() end
|
||||
---@param cb fun(x: BufferController) callback to invoke
|
||||
---invoke callback asynchronously as soon as promise is ready
|
||||
function BufferControllerPromise:and_then(cb) end
|
||||
|
@ -90,6 +106,8 @@ local CursorPromise = {}
|
|||
--- block until promise is ready and return value
|
||||
--- @return Cursor
|
||||
function CursorPromise:await() end
|
||||
--- cancel promise execution
|
||||
function CursorPromise:abort() end
|
||||
---@param cb fun(x: Cursor) callback to invoke
|
||||
---invoke callback asynchronously as soon as promise is ready
|
||||
function CursorPromise:and_then(cb) end
|
||||
|
@ -100,6 +118,8 @@ local MaybeCursorPromise = {}
|
|||
--- block until promise is ready and return value
|
||||
--- @return Cursor | nil
|
||||
function MaybeCursorPromise:await() end
|
||||
--- cancel promise execution
|
||||
function MaybeCursorPromise:abort() end
|
||||
---@param cb fun(x: Cursor | nil) callback to invoke
|
||||
---invoke callback asynchronously as soon as promise is ready
|
||||
function MaybeCursorPromise:and_then(cb) end
|
||||
|
@ -110,6 +130,8 @@ local TextChangePromise = {}
|
|||
--- block until promise is ready and return value
|
||||
--- @return TextChange
|
||||
function TextChangePromise:await() end
|
||||
--- cancel promise execution
|
||||
function TextChangePromise:abort() end
|
||||
---@param cb fun(x: TextChange) callback to invoke
|
||||
---invoke callback asynchronously as soon as promise is ready
|
||||
function TextChangePromise:and_then(cb) end
|
||||
|
@ -120,6 +142,8 @@ local MaybeTextChangePromise = {}
|
|||
--- block until promise is ready and return value
|
||||
--- @return TextChange | nil
|
||||
function MaybeTextChangePromise:await() end
|
||||
--- cancel promise execution
|
||||
function MaybeTextChangePromise:abort() end
|
||||
---@param cb fun(x: TextChange | nil) callback to invoke
|
||||
---invoke callback asynchronously as soon as promise is ready
|
||||
function MaybeTextChangePromise:and_then(cb) end
|
||||
|
|
|
@ -51,6 +51,13 @@ impl LuaUserData for Promise {
|
|||
.map_err(LuaError::runtime)?
|
||||
},
|
||||
});
|
||||
methods.add_method_mut("abort", |_, this, ()| match this.0.take() {
|
||||
None => Err(LuaError::runtime("Promise already awaited")),
|
||||
Some(x) => {
|
||||
x.abort();
|
||||
Ok(())
|
||||
},
|
||||
});
|
||||
methods.add_method_mut("and_then", |_, this, (cb,):(LuaFunction,)| match this.0.take() {
|
||||
None => Err(LuaError::runtime("Promise already awaited")),
|
||||
Some(x) => {
|
||||
|
|
Loading…
Reference in a new issue