@quenty/promise 10.8.0 → 10.9.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -3,6 +3,17 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
+ # [10.9.0](https://github.com/Quenty/NevermoreEngine/compare/@quenty/promise@10.8.0...@quenty/promise@10.9.0) (2024-12-15)
7
+
8
+
9
+ ### Features
10
+
11
+ * Add retry mechanism to UserInfoAggregator ([7ff28b9](https://github.com/Quenty/NevermoreEngine/commit/7ff28b98173b376389496d6d895ba564edf4b337))
12
+
13
+
14
+
15
+
16
+
6
17
  # [10.8.0](https://github.com/Quenty/NevermoreEngine/compare/@quenty/promise@10.7.1...@quenty/promise@10.8.0) (2024-11-06)
7
18
 
8
19
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@quenty/promise",
3
- "version": "10.8.0",
3
+ "version": "10.9.0",
4
4
  "description": "Promise implementation for Roblox",
5
5
  "keywords": [
6
6
  "Roblox",
@@ -27,10 +27,11 @@
27
27
  "dependencies": {
28
28
  "@quenty/deferred": "^2.2.0",
29
29
  "@quenty/loader": "^10.7.1",
30
- "@quenty/maid": "^3.4.0"
30
+ "@quenty/maid": "^3.4.0",
31
+ "@quenty/math": "^2.7.0"
31
32
  },
32
33
  "publishConfig": {
33
34
  "access": "public"
34
35
  },
35
- "gitHead": "00e6f71716216dd6ecbc8505ad898a1ab7f72756"
36
+ "gitHead": "0a20ace4dc7d38f8c889bf73b716b33e8a767c54"
36
37
  }
@@ -0,0 +1,57 @@
1
+ --[=[
2
+ @class PromiseRetryUtils
3
+ ]=]
4
+
5
+ local require = require(script.Parent.loader).load(script)
6
+
7
+ local Promise = require("Promise")
8
+ local Math = require("Math")
9
+
10
+ local PromiseRetryUtils = {}
11
+
12
+ function PromiseRetryUtils.retry(callback, options)
13
+ assert(type(options.initialWaitTime) == "number", "Bad initialWaitTime")
14
+ assert(type(options.maxAttempts) == "number", "Bad maxAttempts")
15
+ assert(type(options.printWarning) == "boolean", "Bad printWarning")
16
+ assert(options.maxAttempts >= 1, "Bad maxAttempts")
17
+
18
+ local promise = Promise.new()
19
+ local isLoopResolved = false
20
+
21
+ local running = task.spawn(function()
22
+ local waitTime = options.initialWaitTime
23
+ local lastResults
24
+
25
+ for attemptNumber=1, options.maxAttempts do
26
+ lastResults = table.pack(callback():Yield())
27
+
28
+ if lastResults[1] then
29
+ isLoopResolved = true
30
+ promise:Resolve(table.unpack(lastResults, 2, lastResults.n))
31
+ return
32
+ end
33
+
34
+ if options.printWarning then
35
+ warn(string.format("[PromiseRetryUtils] - Retrying %d/%d due to failure %q", attemptNumber, options.maxAttempts, tostring(lastResults[2])))
36
+ end
37
+
38
+ task.wait(Math.jitter(waitTime * 2^attemptNumber))
39
+ end
40
+
41
+ isLoopResolved = true
42
+ local errorMessage = string.format("Attempted request %d times before failing with error", tostring(lastResults[2]))
43
+ promise:Reject(errorMessage, table.unpack(lastResults, 3, lastResults.n))
44
+ end)
45
+
46
+ -- Esnure cleanup, but only when we're out of here
47
+ promise:Finally(function()
48
+ if not isLoopResolved then
49
+ task.cancel(running)
50
+ end
51
+ end)
52
+
53
+ return promise
54
+ end
55
+
56
+
57
+ return PromiseRetryUtils