@quenty/bindtocloseservice 3.1.1 → 3.1.2-canary.433.80025dc.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
+ ## [3.1.2-canary.433.80025dc.0](https://github.com/Quenty/NevermoreEngine/compare/@quenty/bindtocloseservice@3.1.1...@quenty/bindtocloseservice@3.1.2-canary.433.80025dc.0) (2023-12-14)
7
+
8
+
9
+ ### Features
10
+
11
+ * Add support for BindToClose to run on client (in plugin and other scenarios) ([8fa0f80](https://github.com/Quenty/NevermoreEngine/commit/8fa0f80b0881e0052a7db11eba68f422e84ef4c5))
12
+
13
+
14
+
15
+
16
+
6
17
  ## [3.1.1](https://github.com/Quenty/NevermoreEngine/compare/@quenty/bindtocloseservice@3.1.0...@quenty/bindtocloseservice@3.1.1) (2023-10-28)
7
18
 
8
19
  **Note:** Version bump only for package @quenty/bindtocloseservice
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@quenty/bindtocloseservice",
3
- "version": "3.1.1",
3
+ "version": "3.1.2-canary.433.80025dc.0",
4
4
  "description": "Bind to game close API in a centralized location.",
5
5
  "keywords": [
6
6
  "Roblox",
@@ -27,13 +27,14 @@
27
27
  "access": "public"
28
28
  },
29
29
  "dependencies": {
30
- "@quenty/loader": "^7.0.0",
31
- "@quenty/promise": "^7.0.0",
32
- "@quenty/symbol": "^2.2.0"
30
+ "@quenty/loader": "7.0.1-canary.433.80025dc.0",
31
+ "@quenty/maid": "2.6.0",
32
+ "@quenty/promise": "7.0.1-canary.433.80025dc.0",
33
+ "@quenty/symbol": "2.2.0"
33
34
  },
34
35
  "devDependencies": {
35
- "@quenty/contentproviderutils": "^7.1.1",
36
- "@quenty/playerthumbnailutils": "^7.0.0"
36
+ "@quenty/contentproviderutils": "7.1.2-canary.433.80025dc.0",
37
+ "@quenty/playerthumbnailutils": "7.0.1-canary.433.80025dc.0"
37
38
  },
38
- "gitHead": "440aca7ce2b50b74317ee05fdc0b8d1e58001af3"
39
+ "gitHead": "80025dcd926765b502d322bb84e013b973409d8c"
39
40
  }
@@ -7,9 +7,12 @@
7
7
 
8
8
  local require = require(script.Parent.loader).load(script)
9
9
 
10
+ local RunService = game:GetService("RunService")
11
+
10
12
  local PromiseUtils = require("PromiseUtils")
11
13
  local Symbol = require("Symbol")
12
14
  local Promise = require("Promise")
15
+ local Maid = require("Maid")
13
16
 
14
17
  local BindToCloseService = {}
15
18
  BindToCloseService.ServiceName = "BindToCloseService"
@@ -17,28 +20,43 @@ BindToCloseService.ServiceName = "BindToCloseService"
17
20
  function BindToCloseService:Init(serviceBag)
18
21
  assert(not self._serviceBag, "Already initialized")
19
22
  self._serviceBag = assert(serviceBag, "No serviceBag")
23
+ self._maid = Maid.new()
20
24
 
21
25
  self._subscriptions = {}
22
26
  end
23
27
 
24
28
  function BindToCloseService:Start()
25
- game:BindToClose(function()
26
- local promises = {}
27
-
28
- for _, caller in pairs(self._subscriptions) do
29
- local promise = caller()
30
- if Promise.isPromise(promise) then
31
- table.insert(promises, promise)
32
- else
33
- warn("[BindToCloseService.BindToClose] - Bad promise returned from close callback.")
29
+ if RunService:IsServer() then
30
+ game:BindToClose(function()
31
+ local ok, err = self:_promiseClose():Yield()
32
+ if not ok then
33
+ warn("[BindToCloseService] - Failed to close all", err)
34
34
  end
35
- end
35
+ end)
36
+
37
+ -- TODO: Also close on cleanup here
38
+ else
39
+ -- This happens when running in a plugin or some other scenario....
40
+
41
+ self._maid:GiveTask(function()
42
+ self:_promiseClose()
43
+ end)
44
+ end
45
+ end
36
46
 
37
- local ok, err = PromiseUtils.all(promises):Yield()
38
- if not ok then
39
- warn("[BindToCloseService] - Failed to close all", err)
47
+ function BindToCloseService:_promiseClose()
48
+ local promises = {}
49
+
50
+ for _, caller in pairs(self._subscriptions) do
51
+ local promise = caller()
52
+ if Promise.isPromise(promise) then
53
+ table.insert(promises, promise)
54
+ else
55
+ warn("[BindToCloseService.BindToClose] - Bad promise returned from close callback.")
40
56
  end
41
- end)
57
+ end
58
+
59
+ return PromiseUtils.all(promises)
42
60
  end
43
61
 
44
62
  --[=[
@@ -59,4 +77,8 @@ function BindToCloseService:RegisterPromiseOnCloseCallback(saveCallback)
59
77
  end
60
78
  end
61
79
 
80
+ function BindToCloseService:Destroy()
81
+ self._maid:DoCleaning()
82
+ end
83
+
62
84
  return BindToCloseService