-
Notifications
You must be signed in to change notification settings - Fork 259
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
23 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,33 @@ | ||
"use strict"; | ||
|
||
class DefaultEvictor { | ||
evict(config, pooledResource, availableObjectsCount) { | ||
const idleTime = Date.now() - pooledResource.lastIdleTime; | ||
evict(config, pooledResource, availableObjectsCount) { | ||
const idleTime = Date.now() - pooledResource.lastIdleTime; | ||
|
||
if (!idleTime) { | ||
console.log('ERROR - idleTime is junk, evictig!', JSON.stringify({ | ||
idleTime, | ||
pooledResource, | ||
})); | ||
return true; | ||
} | ||
|
||
if ( | ||
config.softIdleTimeoutMillis > 0 && | ||
config.softIdleTimeoutMillis < idleTime && | ||
config.min < availableObjectsCount | ||
) { | ||
return true; | ||
} | ||
if (!idleTime) { | ||
console.log( | ||
"ERROR - idleTime is junk, evictig", | ||
JSON.stringify({ | ||
idleTime, | ||
pooledResource | ||
})); | ||
return true; | ||
} | ||
|
||
if (config.idleTimeoutMillis < idleTime) { | ||
return true; | ||
} | ||
if ( | ||
config.softIdleTimeoutMillis > 0 && | ||
config.softIdleTimeoutMillis < idleTime && | ||
config.min < availableObjectsCount | ||
) { | ||
return true; | ||
} | ||
|
||
return false; | ||
if (config.idleTimeoutMillis < idleTime) { | ||
return true; | ||
} | ||
|
||
return false; | ||
} | ||
} | ||
|
||
module.exports = DefaultEvictor; |