Skip to content

Commit 63a2301

Browse files
committed
v0.1.3 - improved memory footprint of module
1 parent 0fb93db commit 63a2301

File tree

3 files changed

+17
-7
lines changed

3 files changed

+17
-7
lines changed

RBXConnectionManager.luau

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,21 @@ local RBXConnectionManager = {}
44
RBXConnectionManager.__index = RBXConnectionManager
55

66
-- Constructor
7-
function RBXConnectionManager.new()
7+
function RBXConnectionManager.new(monitoring_checker_interval: number?)
88
local self = setmetatable({}, RBXConnectionManager)
99
self._connections = {} :: { [string]: RBXScriptConnection }
10+
self._internal_connections = {} :: { RBXScriptConnection }
1011
self._monitoring = {} :: { [string]: any }
1112

12-
-- Cleanup player-specific connections (only for ServerSide)
13-
if RunService:isServer() then
14-
Players.PlayerRemoving:Connect(function(playerObj: Player)
13+
-- Cleanup player-specific connections (server-side feature)
14+
if RunService:IsServer() then
15+
local globalPlayersRemovingConnection = Players.PlayerRemoving:Connect(function(playerObj: Player)
1516
self:DisconnectAllInGroup(tostring(playerObj.UserId))
1617
end)
18+
table.insert(self._internal_connections, globalPlayersRemovingConnection)
1719
end
1820

19-
self:StartMonitoring()
21+
self:StartMonitoring(monitoring_checker_interval)
2022

2123
return self
2224
end
@@ -85,6 +87,14 @@ end
8587

8688
-- Self-destruct
8789
function RBXConnectionManager:Destroy()
90+
-- Disconnect the module's internal connections
91+
for _, connection in pairs(self._internal_connections) do
92+
if connection.Connected then
93+
connection:Disconnect()
94+
end
95+
end
96+
self._internal_connections = {}
97+
8898
self:DisconnectAll()
8999
setmetatable(self, nil)
90100
end

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ RBXConnectionManager is a lightweight and efficient module for managing `RBXScri
1111

1212
## Features
1313
- **Efficient Connection Management**: Easily create, store, and disconnect connections by name.
14-
- **Automatic Cleanup**: Removes player-specific connections when a player leaves (server-side only).
14+
- **Automatic Cleanup**: Removes player-specific connections when a player leaves (server-side feature) -> the player's UserId must be in the connection name.
1515
- **Batch Disconnection**: Disconnect all connections or those within a specific group.
1616
- **Monitoring**: Logs and displays event calls along with timestamps.
1717
- **Self-Destruction**: Provides a method to completely clean up the manager.

wally.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "jarnster/rbxconnectionmanager"
3-
version = "0.1.2"
3+
version = "0.1.3"
44
registry = "https://github.com/UpliftGames/wally-index"
55
realm = "shared"
66

0 commit comments

Comments
 (0)