Comparing version 2.0.1 to 2.1.0
{ | ||
"name": "conclure", | ||
"version": "2.0.1", | ||
"version": "2.1.0", | ||
"description": "Generator runner", | ||
@@ -41,4 +41,4 @@ "type": "module", | ||
"devDependencies": { | ||
"ava": "^3.15.0" | ||
"ava": "^4.3.3" | ||
} | ||
} |
@@ -27,18 +27,10 @@ const TYPE = '@@conclude-effect'; | ||
const running = new WeakMap(); | ||
const resultCache = new WeakMap(); | ||
const finishWatchers = new WeakMap(); | ||
const running = Symbol.for('@@conclude-running'); | ||
const resultCache = Symbol.for('@@conclude-result'); | ||
const finishWatchers = Symbol.for('@@conclude-watchers'); | ||
export function inProgress(it) { | ||
return running.has(it); | ||
} | ||
export const inProgress = it => running in it; | ||
export const finished = it => resultCache in it; | ||
export const getResult = it =>it[resultCache]; | ||
export function finished(it) { | ||
return resultCache.has(it); | ||
} | ||
export function getResult(it) { | ||
return resultCache.get(it); | ||
} | ||
export function whenFinished(it, callback) { | ||
@@ -50,10 +42,10 @@ if (!isFlow(it)) { | ||
if (resultCache.has(it)) { | ||
callback(resultCache.get(it)); | ||
if (resultCache in it) { | ||
callback(it[resultCache]); | ||
return noop; | ||
} | ||
let watchers = finishWatchers.get(it); | ||
let watchers = it[finishWatchers]; | ||
if (!watchers) finishWatchers.set(it, watchers = new Set([callback])); | ||
if (!watchers) watchers = it[finishWatchers] = new Set([callback]); | ||
else watchers.add(callback); | ||
@@ -65,7 +57,7 @@ | ||
function finalize(it, payload) { | ||
resultCache.set(it, payload); | ||
running.delete(it); | ||
it[resultCache] = payload; | ||
delete it[running]; | ||
for (let cb of finishWatchers.get(it) || []) cb(payload); | ||
finishWatchers.delete(it); | ||
for (let cb of it[finishWatchers] || []) cb(payload); | ||
delete it[finishWatchers]; | ||
} | ||
@@ -81,4 +73,4 @@ | ||
if (resultCache.has(it)) { | ||
const { result, error, cancelled } = resultCache.get(it); | ||
if (resultCache in it) { | ||
const { result, error, cancelled } = it[resultCache]; | ||
@@ -93,4 +85,4 @@ if (cancelled) return noop; | ||
if (running.has(it)) { | ||
const subscribe = running.get(it); | ||
if (running in it) { | ||
const subscribe = it[running]; | ||
return subscribe(callback); | ||
@@ -113,3 +105,3 @@ } | ||
if (subscribers.size === 0 && !resultCache.has(it)) { | ||
if (subscribers.size === 0 && !(resultCache in it)) { | ||
finalize(it, { cancelled: true }); | ||
@@ -121,3 +113,3 @@ cancel(); | ||
running.set(it, subscribe); | ||
it[running] = subscribe; | ||
@@ -124,0 +116,0 @@ const unsubscribe = subscribe(callback); |
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
20201
266