You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: src/Features/Cleanup/Janitor.lua
+30-6
Original file line number
Diff line number
Diff line change
@@ -13,19 +13,30 @@ local function getJanitors()
13
13
returnrequire(script.Parent).Janitors
14
14
end
15
15
16
-
--- @classJanitor
17
-
--- Another class.
18
-
19
-
16
+
--[=[
17
+
@class Janitor
18
+
@tag Advanced
19
+
This is an external class which can be referenced with `MapLib:GetFeature("Cleanup").Janitor`
20
+
21
+
Janitor is destructor based class designed to assist with clearing up connections events and references.
22
+
:::warning
23
+
WARNING! This is an advanced feature.
24
+
This page assumes you are familiar, comfortable and can write Luau code.
25
+
:::
26
+
]=]
20
27
--[=[
21
28
@within Janitor
22
29
@since 0.11
30
+
23
31
@function new
24
32
@param name string?
25
33
@return _tasks: {[string]: any}
26
34
@return context: string
27
35
@return name: string?
28
36
@return index: number | string
37
+
@return __index: Janitor
38
+
39
+
Constructs a new Janitor class and is cached for later use. Janitor provides an option in case you want to name your Janitor for easier reference later.
29
40
]=]
30
41
functionJanitor.new(janitorName: string?)
31
42
localself=setmetatable({}, Janitor)
@@ -36,14 +47,19 @@ function Janitor.new(janitorName: string?)
36
47
localjanitors=getJanitors()
37
48
38
49
self.index=janitorNameor#janitors+1
39
-
janitors[self.index] =self
50
+
janitors[self.index] =self
40
51
41
52
returnself
42
53
end
43
54
44
55
--[=[
45
-
@since 0.11
56
+
@within Janitor
57
+
@since 0.11
58
+
@function isJanitor
59
+
@return boolean
60
+
Returns true if the given class is a Janitor, if not it returns false.
This method is used to give Janitor tasks to cleanup, these tasks can be anything, some examples include, functions, threads, coroutines or anything with a .Destroy function.
75
+
:::tip
76
+
Janitor allows for tables to be given in as an argument. If Janitor detects a table it will loop through the table and add anything it finds will be added to the tasks table.
77
+
:::
57
78
]=]
79
+
58
80
functionJanitor:Give(task: any)
59
81
localfunctionhandleTask(subtask: any)
60
82
assert(typeof(task) ~="boolean", "Task cannot be a boolean")
@@ -85,6 +107,8 @@ end
85
107
@method Cleanup
86
108
@param taskTable: table?
87
109
@return nil
110
+
111
+
Calls for the Janitor to cleanup up all the tasks it was given.
0 commit comments