mirror of
https://github.com/AmberGraceRblx/luau-promise.git
synced 2025-04-25 08:00:03 +00:00
Update docs
This commit is contained in:
parent
5541559c78
commit
9e40be2532
2 changed files with 49 additions and 31 deletions
|
@ -83,6 +83,17 @@ docs:
|
||||||
::: tip
|
::: tip
|
||||||
Promises created with [[Promise.async]] don't begin executing until the next `RunService.Heartbeat` event, even if the executor function doesn't yield itself. <a href="/roblox-lua-promise/lib/Details.html#yielding-in-promise-executor">Learn more</a>
|
Promises created with [[Promise.async]] don't begin executing until the next `RunService.Heartbeat` event, even if the executor function doesn't yield itself. <a href="/roblox-lua-promise/lib/Details.html#yielding-in-promise-executor">Learn more</a>
|
||||||
:::
|
:::
|
||||||
|
|
||||||
|
```lua
|
||||||
|
local function waitForChild(instance, childName, timeout)
|
||||||
|
return Promise.async(function(resolve, reject)
|
||||||
|
local child = instance:WaitForChild(childName, timeout)
|
||||||
|
|
||||||
|
;(child and resolve or reject)(child)
|
||||||
|
end)
|
||||||
|
end
|
||||||
|
```
|
||||||
|
|
||||||
static: true
|
static: true
|
||||||
params:
|
params:
|
||||||
- name: asyncExecutor
|
- name: asyncExecutor
|
||||||
|
@ -114,6 +125,42 @@ docs:
|
||||||
desc: "Returns `true` if the Promise was already cancelled at the time of calling `onCancel`."
|
desc: "Returns `true` if the Promise was already cancelled at the time of calling `onCancel`."
|
||||||
returns: Promise
|
returns: Promise
|
||||||
|
|
||||||
|
- name: promisify
|
||||||
|
desc: |
|
||||||
|
Wraps a function that yields into one that returns a Promise.
|
||||||
|
|
||||||
|
```lua
|
||||||
|
local sleep = Promise.promisify(wait)
|
||||||
|
|
||||||
|
sleep(1):andThen(print)
|
||||||
|
```
|
||||||
|
|
||||||
|
```lua
|
||||||
|
local isPlayerInGroup = Promise.promisify(function(player, groupId)
|
||||||
|
return player:IsInGroup(groupId)
|
||||||
|
end)
|
||||||
|
```
|
||||||
|
static: true
|
||||||
|
params:
|
||||||
|
- name: function
|
||||||
|
type:
|
||||||
|
kind: function
|
||||||
|
params: "...: ...any?"
|
||||||
|
- name: selfValue
|
||||||
|
type: any?
|
||||||
|
desc: This value will be prepended to the arguments list given to the curried function. This can be used to lock a method to a single instance. Otherwise, you can pass the self value before the argument list.
|
||||||
|
returns:
|
||||||
|
- desc: The function acts like the passed function but now returns a Promise of its return values.
|
||||||
|
type:
|
||||||
|
kind: function
|
||||||
|
params:
|
||||||
|
- name: "..."
|
||||||
|
type: "...any?"
|
||||||
|
desc: The same arguments the wrapped function usually takes.
|
||||||
|
returns:
|
||||||
|
- name: "*"
|
||||||
|
desc: The return values from the wrapped function.
|
||||||
|
|
||||||
- name: resolve
|
- name: resolve
|
||||||
desc: Creates an immediately resolved Promise with the given value.
|
desc: Creates an immediately resolved Promise with the given value.
|
||||||
static: true
|
static: true
|
||||||
|
@ -158,35 +205,6 @@ docs:
|
||||||
params: "...: ...any?"
|
params: "...: ...any?"
|
||||||
- name: "..."
|
- name: "..."
|
||||||
type: "...any?"
|
type: "...any?"
|
||||||
- name: promisify
|
|
||||||
desc: |
|
|
||||||
Wraps a function that yields into one that returns a Promise.
|
|
||||||
|
|
||||||
```lua
|
|
||||||
local sleep = Promise.promisify(wait)
|
|
||||||
|
|
||||||
sleep(1):andThen(print)
|
|
||||||
```
|
|
||||||
static: true
|
|
||||||
params:
|
|
||||||
- name: function
|
|
||||||
type:
|
|
||||||
kind: function
|
|
||||||
params: "...: ...any?"
|
|
||||||
- name: selfValue
|
|
||||||
type: any?
|
|
||||||
desc: This value will be prepended to the arguments list given to the curried function. This can be used to lock a method to a single instance. Otherwise, you can pass the self value before the argument list.
|
|
||||||
returns:
|
|
||||||
- desc: The function acts like the passed function but now returns a Promise of its return values.
|
|
||||||
type:
|
|
||||||
kind: function
|
|
||||||
params:
|
|
||||||
- name: "..."
|
|
||||||
type: "...any?"
|
|
||||||
desc: The same arguments the wrapped function usually takes.
|
|
||||||
returns:
|
|
||||||
- name: "*"
|
|
||||||
desc: The return values from the wrapped function.
|
|
||||||
|
|
||||||
# Instance methods
|
# Instance methods
|
||||||
- name: andThen
|
- name: andThen
|
||||||
|
@ -273,7 +291,7 @@ docs:
|
||||||
|
|
||||||
```lua
|
```lua
|
||||||
promise:andThen(function()
|
promise:andThen(function()
|
||||||
return callback(...args)
|
return someFunction("some", "arguments")
|
||||||
end)
|
end)
|
||||||
```
|
```
|
||||||
params:
|
params:
|
||||||
|
|
|
@ -68,7 +68,7 @@ end)
|
||||||
|
|
||||||
You must observe the result of a Promise, either with `catch` or `finally`, otherwise an unhandled Promise rejection warning will be printed to the console.
|
You must observe the result of a Promise, either with `catch` or `finally`, otherwise an unhandled Promise rejection warning will be printed to the console.
|
||||||
|
|
||||||
If an error occurs while executing the Promise body, the Promise will be rejected automatically with the error text.
|
If an error occurs while executing the Promise body, the Promise will be rejected automatically with the error text if it's in a synchronous Promise. Otherwise, the error won't be caught.
|
||||||
|
|
||||||
## Chaining
|
## Chaining
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue