@nxtedition/agent
Advanced tools
Comparing version 1.0.7 to 1.0.8
42
index.js
const objectHash = require('object-hash') | ||
const { Observable } = require('rxjs') | ||
@@ -12,48 +11,7 @@ function hashObject (obj) { | ||
const providers = new Map() | ||
setInterval(() => { | ||
for (const [ key, provider ] of providers) { | ||
if (provider.refs === 0) { | ||
provider.unsubscribe() | ||
providers.delete(key) | ||
} | ||
} | ||
}, 60000) | ||
module.exports = { | ||
observe (query, prop) { | ||
const ds = this | ||
const hash = hashObject(query) | ||
return Observable | ||
.using( | ||
() => { | ||
let provider = providers.get(hash) | ||
if (!provider) { | ||
provider = { | ||
unsubscribe: ds.record.provide(`${hash}:agent.query`, () => Observable.of(query)), | ||
refs: 0 | ||
} | ||
providers.set(hash, provider) | ||
} | ||
provider.refs += 1 | ||
return { | ||
unsubscribe: () => { | ||
provider.refs -= 1 | ||
} | ||
} | ||
}, | ||
() => ds.record.observe(`${hash}:agent${prop ? `.${prop}` : ``}`) | ||
) | ||
}, | ||
spawn (query, prop) { | ||
const ds = this | ||
const hash = hashObject(query) | ||
ds.record.set(`${hash}:agent.query`, query) | ||
return ds.record.observe(`${hash}:agent${prop ? `.${prop}` : ``}`) | ||
@@ -60,0 +18,0 @@ }, |
{ | ||
"name": "@nxtedition/agent", | ||
"version": "1.0.7", | ||
"version": "1.0.8", | ||
"main": "index.js", | ||
@@ -5,0 +5,0 @@ "author": "Robert Nagy <robert.nagy@boffins.se>", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
2510
24