Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/core-manager/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ export class CoreManager extends TypedEmitter {
projectKey,
projectSecretKey,
encryptionKeys = {},
storage
storage,
}) {
super()
assert(
Expand Down
30 changes: 30 additions & 0 deletions lib/core-manager/random-access-file-pool.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/**
* File descriptor pool for random-access-storage to limit the number of file
* descriptors used. Important particularly for Android where the hard limit for
* the app is 1024.
*/
export class RandomAccessFilePool {
/** @param {number} maxSize max number of file descriptors to use */
constructor (maxSize) {
this.maxSize = maxSize
/** @type {Set<import('random-access-file')>} */
this.active = new Set()
}

/** @param {import('random-access-file')} file */
_onactive (file) {
if (this.active.size >= this.maxSize) {
// suspend least recently inserted this manually iterates in insertion
// order, but only iterates to the first one (least recently inserted)
const toSuspend = this.active[Symbol.iterator]().next().value
toSuspend.suspend()
this.active.delete(toSuspend)
}
this.active.add(file)
}

/** @param {import('random-access-file')} file */
_oninactive (file) {
this.active.delete(file)
}
}
172 changes: 155 additions & 17 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,10 @@
"eslint-config-prettier": "^8.8.0",
"nanobench": "^3.0.0",
"prettier": "^2.8.8",
"random-access-file": "^4.0.4",
"random-access-memory": "^6.2.0",
"rimraf": "^5.0.0",
"tempy": "^3.1.0",
"ts-proto": "^1.147.1",
"type-fest": "^3.10.0",
"typedoc": "^0.24.6",
Expand All @@ -69,7 +71,7 @@
"b4a": "^1.6.3",
"base32.js": "^0.1.0",
"better-sqlite3": "^8.3.0",
"corestore": "^6.5.2",
"corestore": "^6.8.4",
"hypercore": "^10.9.0",
"hypercore-crypto": "^3.3.1",
"hyperdrive": "^11.0.0-alpha.10",
Expand Down
Loading