Commit graph

104 commits

Author SHA1 Message Date
Amber's Careware
558b61fe3d Initial forked version 2022-10-24 20:14:27 -06:00
eryn L. K
fa7a0d67ac Fix retry docs
Closes #82
2022-03-02 19:03:54 -05:00
eryn L. K
cab1c5ec8b Fix unhandled rejection warning with await
Closes #80
2022-03-02 19:02:21 -05:00
eryn L. K
e192db7946 Fix bug with Promise.fold
Closes #77
2022-01-02 23:18:12 -05:00
eryn L. K
06fc407f12 Update docs for v4 2021-12-28 05:29:09 -05:00
eryn L. K
893c43a90c Cancel finally returned promise if outer cancelled 2021-12-28 05:24:19 -05:00
eryn L. K
afc245c4f1 Change behavior of finally
Closes #59
Closes #66
2021-12-28 04:23:54 -05:00
eryn L. K
2cb2eec152 Don't call queued callbacks from cancelled sub-promise
Closes #67
2021-12-27 23:15:44 -05:00
eryn L. K
34273a7efc Close promise thread on finalize and cancel
Closes #76
2021-12-27 23:04:47 -05:00
eryn L. K
54e510d909 Use task.spawn instead of BindableEvent for await 2021-12-27 22:41:42 -05:00
eryn L. K
3138dab77a Implement Promise.retryWithDelay
Closes #45
2021-12-27 22:23:18 -05:00
eryn L. K
eb3f2e77e2 Add since to onUnhandledRejection 2021-12-27 22:08:54 -05:00
eryn L. K
9e51c039f7 Add onUnhandledRejection
Closes #54
2021-12-27 22:06:42 -05:00
eryn L. K
4e04458816 Support callable tables where functions are allowed
Closes #64
2021-12-27 21:46:19 -05:00
eryn L. K
0b8d55a4c3 Fix docs typo
Closes #74
2021-12-27 21:30:42 -05:00
eryn L. K
079bd8e6f5 Update doc comments for new moonwave version 2021-12-27 21:28:28 -05:00
eryn L. K
b80fa76bc8 Fix promise.resolve example 2021-11-24 17:29:16 -05:00
eryn L. K
6c38e41422 Format with stylua 2021-11-24 17:28:49 -05:00
eryn L. K
81dc283f32 Fix onCancel type 2021-10-23 15:52:36 -04:00
Eryn Lynn
df750d4a11 update docs 2021-09-30 03:01:59 -04:00
Eryn Lynn
3f77076707 Update to use moonwave docs 2021-09-23 19:08:38 -04:00
howmanysmall
72f100473d
Fix linting (#49) 2021-03-18 20:43:49 -04:00
otrepanier
ce6c12f177 remove promise check 2020-11-30 16:42:21 -08:00
otrepanier
1ac7d3cae9 refactor implementation to support cancel 2020-11-30 16:34:13 -08:00
otrepanier
4fc7792c0c implement Promise.fold 2020-11-20 14:14:27 -08:00
Eryn Lynn
e7a01c7bed Fix #39 2020-08-24 13:34:36 -04:00
Eryn Lynn
eafa18be87 Merge branch 'master' into pr/40 2020-08-24 13:22:16 -04:00
Eryn Lynn
d47d597259 Fix #41 2020-08-24 13:20:47 -04:00
Niles
3a96a1d2a7
Allow OnCancel to break out of the current loop 2020-08-22 03:49:59 -05:00
Niles
313d1cb6ab
Revert back to Promise._timeEvent and Promise._getTime statics 2020-08-07 00:52:41 -05:00
Niles
d1ff9be774
Promise.delay fix 2020-07-16 05:51:54 -05:00
Eryn Lynn
13ae48a5ee Fix #31 2020-07-10 23:45:47 -04:00
howmanysmall
dde1c6517e
Update init.lua
- [Prefer calling string functions directly](https://developer.roblox.com/en-us/resources/release-note/Release-Notes-for-433)
- Fixed spaces being used in `Promise.retry`.
- Fixed `Promise:done` calling itself `Promise:finallyO` in the assert. (intentional?)
- Prefer using the first return of `ipairs` to add a Promise to the array instead of `table.insert`.
- Removed the unused `reject` in `Promise._try`
- Trailing commas as per Roblox Lua style guide.

Other suggestions:

- You could use `table.create` in `Promise:timeout` like so:

```Lua
function Promise.prototype:timeout(seconds, rejectionValue)
	local traceback = debug.traceback(nil, 2)

	local racedPromises = table.create(2)
	racedPromises[1] = Promise.delay(seconds):andThen(function()
		return Promise.reject(rejectionValue == nil and Error.new({
			kind = Error.Kind.TimedOut,
			error = "Timed out",
			context = string.format(
				"Timeout of %d seconds exceeded.\n:timeout() called at:\n\n%s",
				seconds,
				traceback
			),
		}) or rejectionValue)
	end)

	racedPromises[2] = self
	return Promise.race(racedPromises)
end
```
2020-06-09 12:53:06 -06:00
Eryn Lynn
b4ba6d2414 Add Promise.fromEvent
closes #14
2020-05-29 02:10:45 -04:00
Eryn Lynn
e5843cf5a2 Add Promise.retry
Closes #16
2020-05-29 02:10:29 -04:00
Eryn Lynn
0c0d7f0464 Add Promise.each
closes #21
2020-05-13 19:48:45 -04:00
Eryn Lynn
1ad5ab8b3e fix capitalization 2020-05-11 15:43:58 -04:00
Eryn Lynn
fc134adb73 mprove Promise.delay accuracy 2020-05-11 15:43:50 -04:00
Eryn Lynn
266e265e20 Allow rejection with error objects 2020-05-11 15:43:35 -04:00
Eryn Lynn
faa4f73dd3 Add Promise:now()
closes #23
2020-05-06 19:22:48 -04:00
Eryn Lynn
ff345ea31b Expose & refactor RuntimeError 2020-05-06 18:02:10 -04:00
Eryn Lynn
292e47293c Let Promise:expect() throw rejection objects 2020-05-06 14:20:34 -04:00
Eryn Lynn
1ca3fff6f5 Use xpcall, revamp error handling 2020-05-04 23:56:49 -04:00
James Onnen
ffd4cd94a1
Avoid reallocating another table for the _consumers() metatable, leading to a 5%-10% speed up of the trivial Promise.new(function() end) case 2020-03-29 03:35:15 -07:00
Eryn Lynn
5a4a30e221 Fix broken tests 2020-02-28 21:21:01 -05:00
Niles
4e6b0de633
Update init.lua 2020-02-14 15:08:53 -06:00
Niles
e1e183d632
Optimize Promise.delay with linked-list impl
- Always iterate over promises via `ipairs`
- Avoid pushing the call arguments stack to a table in Promise.prototype.expect and Promise.prototype.await
- Use a doubly-linked list implementation of a queue

The old queue/dequeue implementation used an array which:
    - has items removed from the front (`table.remove(queue, 1)` O(n) each time)
        - this is especially bad in the main loop which could run multiple times in-a-row on a large array
        - new: O(1)
    - uses table.insert() followed by table.sort() to add a new node (O(n log n))
        - new: O(n)
    - has to lookup the index of the node being dequeued (O(n))
        - new: O(1)
2020-02-14 06:02:48 -06:00
Eryn Lynn
64ba0099f1 Pass error to executor runner 2020-02-12 19:59:04 -05:00
Eryn Lynn
87937962ad Add traceback piping to more functions 2020-02-12 18:55:29 -05:00
Eryn Lynn
4ecdd156a5 awaitvalue -> expect 2019-11-12 23:14:18 -05:00