@@ -14,14 +14,14 @@ local Types = require (script.Parent.Parent.Types)
1414type Connection = Types .Connection
1515type QueryConfig <R , S > = Types .QueryConfig <R , S >
1616
17- -- Constants --------------------------------------------------------------
17+ -- Constants ----------------------------------------------------------
1818
1919local IS_SERVER = RunService :IsServer ()
2020
2121-- Wire ceiling: correlationId is u16 in Channel.writeQuery / Reader.process.
2222local POOL_SIZE = 65536
2323
24- -- State ------------------------------------------------------------------
24+ -- State --------------------------------------------------------------
2525
2626type PendingQuery = {
2727 thread : thread ? ,
@@ -33,7 +33,7 @@ local _pending = {} :: { [number]: PendingQuery }
3333local _nextId = 0
3434local _activeCount = 0
3535
36- -- Private ----------------------------------------------------------------
36+ -- Private ------------------------------------------------------------
3737
3838local function allocCorrelation (): number
3939 if _activeCount >= POOL_SIZE then
@@ -53,7 +53,9 @@ local function allocCorrelation (): number
5353 return id
5454end
5555
56- local function freeCorrelation (): ()
56+ -- Decrements the active correlation counter. Does not free a specific slot;
57+ -- that is handled by nil-ing _pending[id] at the call site.
58+ local function releaseCorrelation (): ()
5759 _activeCount -= 1
5860end
5961
@@ -64,7 +66,7 @@ local function completeQuery (id: number, data: any): ()
6466 end
6567
6668 _pending [id ] = nil
67- freeCorrelation ()
69+ releaseCorrelation ()
6870
6971 if entry .timeout then
7072 task .cancel (entry .timeout )
@@ -158,7 +160,7 @@ local function requestMulti (self: any, players: { Player }, data: any): { [Play
158160 local entry = _pending [cid ]
159161 if entry then
160162 _pending [cid ] = nil
161- freeCorrelation ()
163+ releaseCorrelation ()
162164 end
163165 end
164166
@@ -176,8 +178,6 @@ local function requestMulti (self: any, players: { Player }, data: any): { [Play
176178 return coroutine.yield ()
177179end
178180
179- -- Query ------------------------------------------------------------------
180-
181181local QueryImpl = {}
182182QueryImpl .__index = QueryImpl
183183
@@ -274,7 +274,9 @@ function QueryImpl.requestGroup (self: any, group: any, data: any): { [Player]:
274274 return requestMulti (self , players , data )
275275end
276276
277- -- Public -----------------------------------------------------------------
277+ table.freeze (QueryImpl )
278+
279+ -- Public -------------------------------------------------------------
278280
279281local Query = {}
280282
0 commit comments