diff --git a/lib/README.md b/lib/README.md index 368db4a..4adf8c1 100644 --- a/lib/README.md +++ b/lib/README.md @@ -83,6 +83,17 @@ docs: ::: 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. Learn more ::: + + ```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 params: - name: asyncExecutor @@ -113,6 +124,42 @@ docs: - type: boolean desc: "Returns `true` if the Promise was already cancelled at the time of calling `onCancel`." 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 desc: Creates an immediately resolved Promise with the given value. @@ -158,35 +205,6 @@ docs: params: "...: ...any?" - name: "..." 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 - name: andThen @@ -273,7 +291,7 @@ docs: ```lua promise:andThen(function() - return callback(...args) + return someFunction("some", "arguments") end) ``` params: diff --git a/lib/Usage.md b/lib/Usage.md index fb0347d..2515a54 100644 --- a/lib/Usage.md +++ b/lib/Usage.md @@ -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. -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