@web4/bitdrive
Version:
Bitdrive is a secure, real time distributed file system
30 lines (25 loc) • 628 B
JavaScript
const mutexify = require('mutexify')
const CONTENT_LOCK = Symbol('BitdriveContentLock')
function contentOptions (self) {
return {
sparse: self.sparse || self.latest,
maxRequests: self.maxRequests,
storageCacheSize: self.contentStorageCacheSize
}
}
class ContentState {
constructor (feed) {
this.feed = (feed instanceof ContentState) ? feed.feed : feed
if (!this.feed[CONTENT_LOCK]) this.feed[CONTENT_LOCK] = mutexify()
}
lock (cb) {
return this.feed[CONTENT_LOCK](cb)
}
isLocked () {
return this.feed[CONTENT_LOCK].locked
}
}
module.exports = {
contentOptions,
ContentState
}