UNPKG

630 BJavaScriptView Raw
1const mutexify = require('mutexify')
2
3const CONTENT_LOCK = Symbol('HyperdriveContentLock')
4
5function contentOptions (self) {
6 return {
7 sparse: self.sparse || self.latest,
8 maxRequests: self.maxRequests,
9 storageCacheSize: self.contentStorageCacheSize
10 }
11}
12
13class ContentState {
14 constructor (feed) {
15 this.feed = (feed instanceof ContentState) ? feed.feed : feed
16 if (!this.feed[CONTENT_LOCK]) this.feed[CONTENT_LOCK] = mutexify()
17 }
18 lock (cb) {
19 return this.feed[CONTENT_LOCK](cb)
20 }
21 isLocked () {
22 return this.feed[CONTENT_LOCK].locked
23 }
24}
25
26module.exports = {
27 contentOptions,
28 ContentState
29}