@quenty/promise 6.3.0 → 6.4.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
+ # [6.4.0](https://github.com/Quenty/NevermoreEngine/compare/@quenty/promise@6.3.0...@quenty/promise@6.4.0) (2023-03-31)
7
+
8
+
9
+ ### Features
10
+
11
+ * Add PromiseUtils.combine(stateTable) ([1cb3606](https://github.com/Quenty/NevermoreEngine/commit/1cb36067fa80e7a86746dbee9f1fa07f9f9766bf))
12
+
13
+
14
+
15
+
16
+
6
17
  # [6.3.0](https://github.com/Quenty/NevermoreEngine/compare/@quenty/promise@6.2.0...@quenty/promise@6.3.0) (2023-03-05)
7
18
 
8
19
  **Note:** Version bump only for package @quenty/promise
package/LICENSE.md CHANGED
@@ -1,6 +1,6 @@
1
1
  MIT License
2
2
 
3
- Copyright (c) 2014-2022 Quenty
3
+ Copyright (c) 2014-2023 James Onnen (Quenty)
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@quenty/promise",
3
- "version": "6.3.0",
3
+ "version": "6.4.0",
4
4
  "description": "Promise implementation for Roblox",
5
5
  "keywords": [
6
6
  "Roblox",
@@ -32,5 +32,5 @@
32
32
  "publishConfig": {
33
33
  "access": "public"
34
34
  },
35
- "gitHead": "e62b5eac2e5d9084ab9083f128452dd2d98b6f1a"
35
+ "gitHead": "2a1c35a8d2e90b291a83a6e2def0ec69f3f24837"
36
36
  }
@@ -74,6 +74,44 @@ function PromiseUtils.all(promises)
74
74
  return returnPromise
75
75
  end
76
76
 
77
+ --[=[
78
+ Combines the result of promises together
79
+
80
+ @param stateTable any
81
+ @return Promise<any>
82
+ ]=]
83
+ function PromiseUtils.combine(stateTable)
84
+ assert(type(stateTable) == "table", "Bad stateTable")
85
+
86
+ local remainingCount = 0
87
+ for _, _ in pairs(stateTable) do
88
+ remainingCount = remainingCount + 1
89
+ end
90
+
91
+ local returnPromise = Promise.new()
92
+ local results = {}
93
+ local allFulfilled = true
94
+
95
+ local function syncronize(key, isFullfilled)
96
+ return function(value)
97
+ allFulfilled = allFulfilled and isFullfilled
98
+ results[key] = value
99
+ remainingCount = remainingCount - 1
100
+
101
+ if remainingCount == 0 then
102
+ local method = allFulfilled and "Resolve" or "Reject"
103
+ returnPromise[method](returnPromise, results)
104
+ end
105
+ end
106
+ end
107
+
108
+ for key, promise in pairs(stateTable) do
109
+ promise:Then(syncronize(key, true), syncronize(key, false))
110
+ end
111
+
112
+ return returnPromise
113
+ end
114
+
77
115
  --[=[
78
116
  Inverts the result of a promise, turning a resolved promise
79
117
  into a rejected one, and a rejected one into a resolved one.