@quenty/maid 3.3.0 → 3.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 +16 -0
- package/package.json +2 -2
- package/src/Shared/Maid.lua +27 -19
- package/src/Shared/MaidTaskUtils.lua +17 -14
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,22 @@
|
|
|
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.4.0](https://github.com/Quenty/NevermoreEngine/compare/@quenty/maid@3.3.0...@quenty/maid@3.4.0) (2024-10-04)
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
### Bug Fixes
|
|
10
|
+
|
|
11
|
+
* Maid:Add reports the correct method name in error ([3d31b0d](https://github.com/Quenty/NevermoreEngine/commit/3d31b0d5c6aa7c3bf280e102b1b37a3219ef2dba))
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
### Performance Improvements
|
|
15
|
+
|
|
16
|
+
* Order maid tasks by most common access scenarios and reduce query of typeof() calls ([2f6c713](https://github.com/Quenty/NevermoreEngine/commit/2f6c7130f462188e77ee4789315e5692302280eb))
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
|
|
6
22
|
# [3.3.0](https://github.com/Quenty/NevermoreEngine/compare/@quenty/maid@3.2.0...@quenty/maid@3.3.0) (2024-09-12)
|
|
7
23
|
|
|
8
24
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@quenty/maid",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.4.0",
|
|
4
4
|
"description": "Easily cleanup event listeners and objects in Roblox",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"Roblox",
|
|
@@ -29,5 +29,5 @@
|
|
|
29
29
|
"publishConfig": {
|
|
30
30
|
"access": "public"
|
|
31
31
|
},
|
|
32
|
-
"gitHead": "
|
|
32
|
+
"gitHead": "035abfa088c854a73e1c65b350267eaa17669646"
|
|
33
33
|
}
|
package/src/Shared/Maid.lua
CHANGED
|
@@ -103,34 +103,39 @@ function Maid:__newindex(index, newTask)
|
|
|
103
103
|
end
|
|
104
104
|
|
|
105
105
|
local tasks = self._tasks
|
|
106
|
-
local
|
|
106
|
+
local job = tasks[index]
|
|
107
107
|
|
|
108
|
-
if
|
|
108
|
+
if job == newTask then
|
|
109
109
|
return
|
|
110
110
|
end
|
|
111
111
|
|
|
112
112
|
tasks[index] = newTask
|
|
113
113
|
|
|
114
|
-
if
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
114
|
+
if job then
|
|
115
|
+
local jobType = typeof(job)
|
|
116
|
+
if jobType == "function" then
|
|
117
|
+
job()
|
|
118
|
+
elseif jobType == "table" then
|
|
119
|
+
if type(job.Destroy) == "function" then
|
|
120
|
+
job:Destroy()
|
|
121
|
+
end
|
|
122
|
+
elseif jobType == "Instance" then
|
|
123
|
+
job:Destroy()
|
|
124
|
+
elseif jobType == "thread" then
|
|
118
125
|
local cancelled
|
|
119
|
-
if coroutine.running() ~=
|
|
126
|
+
if coroutine.running() ~= job then
|
|
120
127
|
cancelled = pcall(function()
|
|
121
|
-
task.cancel(
|
|
128
|
+
task.cancel(job)
|
|
122
129
|
end)
|
|
123
130
|
end
|
|
124
131
|
|
|
125
132
|
if not cancelled then
|
|
126
133
|
task.defer(function()
|
|
127
|
-
task.cancel(
|
|
134
|
+
task.cancel(job)
|
|
128
135
|
end)
|
|
129
136
|
end
|
|
130
|
-
elseif
|
|
131
|
-
|
|
132
|
-
elseif oldTask.Destroy then
|
|
133
|
-
oldTask:Destroy()
|
|
137
|
+
elseif jobType == "RBXScriptConnection" then
|
|
138
|
+
job:Disconnect()
|
|
134
139
|
end
|
|
135
140
|
end
|
|
136
141
|
end
|
|
@@ -149,7 +154,7 @@ function Maid:Add(task)
|
|
|
149
154
|
self[#self._tasks+1] = task
|
|
150
155
|
|
|
151
156
|
if type(task) == "table" and (not task.Destroy) then
|
|
152
|
-
warn("[Maid.
|
|
157
|
+
warn("[Maid.Add] - Gave table task without .Destroy\n\n" .. debug.traceback())
|
|
153
158
|
end
|
|
154
159
|
|
|
155
160
|
return task
|
|
@@ -229,9 +234,14 @@ function Maid:DoCleaning()
|
|
|
229
234
|
local index, job = next(tasks)
|
|
230
235
|
while job ~= nil do
|
|
231
236
|
tasks[index] = nil
|
|
232
|
-
|
|
237
|
+
local jobType = typeof(job)
|
|
238
|
+
if jobType == "function" then
|
|
233
239
|
job()
|
|
234
|
-
elseif type(job) == "
|
|
240
|
+
elseif jobType == "table" and type(job.Destroy) == "function" then
|
|
241
|
+
job:Destroy()
|
|
242
|
+
elseif jobType == "Instance" then
|
|
243
|
+
job:Destroy()
|
|
244
|
+
elseif jobType == "thread" then
|
|
235
245
|
local cancelled
|
|
236
246
|
if coroutine.running() ~= job then
|
|
237
247
|
cancelled = pcall(function()
|
|
@@ -245,10 +255,8 @@ function Maid:DoCleaning()
|
|
|
245
255
|
task.cancel(toCancel)
|
|
246
256
|
end)
|
|
247
257
|
end
|
|
248
|
-
elseif
|
|
258
|
+
elseif jobType == "RBXScriptConnection" then
|
|
249
259
|
job:Disconnect()
|
|
250
|
-
elseif job.Destroy then
|
|
251
|
-
job:Destroy()
|
|
252
260
|
end
|
|
253
261
|
index, job = next(tasks)
|
|
254
262
|
end
|
|
@@ -23,11 +23,12 @@ local MaidTaskUtils = {}
|
|
|
23
23
|
@return boolean
|
|
24
24
|
]=]
|
|
25
25
|
function MaidTaskUtils.isValidTask(job)
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
or
|
|
29
|
-
or
|
|
30
|
-
or
|
|
26
|
+
local jobType = typeof(job)
|
|
27
|
+
return jobType == "function"
|
|
28
|
+
or jobType == "thread"
|
|
29
|
+
or jobType == "RBXScriptConnection"
|
|
30
|
+
or jobType == "Instance"
|
|
31
|
+
or (jobType == "table" and type(job.Destroy) == "function")
|
|
31
32
|
end
|
|
32
33
|
|
|
33
34
|
--[=[
|
|
@@ -36,9 +37,16 @@ end
|
|
|
36
37
|
@param job MaidTask -- Task to execute
|
|
37
38
|
]=]
|
|
38
39
|
function MaidTaskUtils.doTask(job)
|
|
39
|
-
|
|
40
|
+
local jobType = typeof(job)
|
|
41
|
+
if jobType == "function" then
|
|
40
42
|
job()
|
|
41
|
-
elseif
|
|
43
|
+
elseif jobType == "table" then
|
|
44
|
+
if type(job.Destroy) == "function" then
|
|
45
|
+
job:Destroy()
|
|
46
|
+
end
|
|
47
|
+
elseif jobType == "Instance" then
|
|
48
|
+
job:Destroy()
|
|
49
|
+
elseif jobType == "thread" then
|
|
42
50
|
local cancelled
|
|
43
51
|
if coroutine.running() ~= job then
|
|
44
52
|
cancelled = pcall(function()
|
|
@@ -51,15 +59,10 @@ function MaidTaskUtils.doTask(job)
|
|
|
51
59
|
task.cancel(job)
|
|
52
60
|
end)
|
|
53
61
|
end
|
|
54
|
-
elseif
|
|
62
|
+
elseif jobType == "RBXScriptConnection" then
|
|
55
63
|
job:Disconnect()
|
|
56
|
-
elseif type(job) == "table" and type(job.Destroy) == "function" then
|
|
57
|
-
job:Destroy()
|
|
58
|
-
-- selene: allow(if_same_then_else)
|
|
59
|
-
elseif typeof(job) == "Instance" then
|
|
60
|
-
job:Destroy()
|
|
61
64
|
else
|
|
62
|
-
error("Bad job")
|
|
65
|
+
error(string.format("[MaidTaskUtils.doTask] - Bad job of type %q", typeof(job)))
|
|
63
66
|
end
|
|
64
67
|
end
|
|
65
68
|
|