-
Notifications
You must be signed in to change notification settings - Fork 16
/
generic-pool.node.txt
51 lines (46 loc) · 4.37 KB
/
generic-pool.node.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
GENERIC-POOL
VERSION ==> #2.1.1
GENERIC-POOL.Pool(OBJ) #Returns POOL of MY_OBJ.
#OBJ:
# - name STR (def: undefined)
# - can be get by POOL.getName()
# - create(FUNC2(ERROR, MY_OBJ))
# - POOL.acquire(FUNC(ERROR, MY_OBJ)[, NUM2]):
# - if previously released MY_OBJ available, take it
# - otherwise fire create(), adding MY_OBJ to the pool
# - NUM2 is the priority (def: 0) (see below)
# - returns true if reached max
# - destroy(MY_OBJ)
# - check MY_OBJ by copy (===) not reference
# - POOL.release(MY_OBJ) doesn't fire destroy(): it makes MYOBJ available in the pool instead
# - max NUM (def: 1): at NUM VAL3 in the pool, acquisitions waits in a queue
# - queue is according to priority NUM2
# - lower is better
# - max is priorityRange NUM (def: 1)
# - min NUM (def: 0): at NUM VAL3 in the pool, releases doesn't release
# - at start, NUM are created
# - idleTimeoutMillis NUM (def: 30000): if available MY_OBJ hasn't been acquired after NUMms,
# destroy it
# - checked every reapIntervalMillis NUMms (def: 1000)
# - if refreshIdle true (def), also release MY_OBJ even if < min NUM (but will recreate it
# automatically right away)
# - returnToHead BOOL: if true, available objects are a FIFO not a FILO (for idle timeouts)
# - validate(MY_OBJ)->BOOL:
# - called when acquired available MY_OBJ
# - If false, destroy available MY_OBJ and try next available one instead
# - log BOOL|FUNC(STR, LEVEL): verbose
#Node doesn't terminate until all MY_OBJ have been released:
# - so when program stops and all release, min. of idleTimeoutMillis until destroyed
# - if min > 0, needs to POOL.drain(FUNC()) to set min to 0 and refuse new acquisitions
# - if refreshIdle false, will not release minimum ones (need to call POOL.destroyAllNow())
# - to release everything now, do POOL.drain(function(){ POOL.destroyAllNow(); })
POOL.getPoolSize() #Number of clients used + previously used
POOL.availableObjectsCount() #Clients previously used, available in the pool
POOL.waitingClientsCount() #Waiting clients
POOL.pooled(FUNC(MY_OBJ #Returns FUNC3([VAL..., ][FUNC4(...)]):
[, VAL...]FUNC2(...))) # - fires FUNC(), which acquire(MY_OBJ)
# - when FUNC2(...) is called:
# - Auto-release MY_OBJ
# - fires FUNC4(...)