fix a rushed sloppy update...

Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
Alex A. Naanou 2022-12-29 02:56:19 +03:00
parent b47ebfbdc6
commit 4718d5e443
2 changed files with 15 additions and 2 deletions

View File

@ -1,6 +1,6 @@
{ {
"name": "ig-stoppable", "name": "ig-stoppable",
"version": "2.0.2", "version": "2.0.3",
"description": "Utility library implementing tooling to make stoppable functions...", "description": "Utility library implementing tooling to make stoppable functions...",
"main": "stoppable.js", "main": "stoppable.js",
"scripts": { "scripts": {

View File

@ -67,6 +67,7 @@ var AsyncGenerator =
// //
// NOTE: this repeats the same code at lest twice, not sure yet how to avoid // NOTE: this repeats the same code at lest twice, not sure yet how to avoid
// this... // this...
// XXX need to give onstop(..) access to the actual call context...
module = module =
function(func, onstop){ function(func, onstop){
return Object.assign( return Object.assign(
@ -78,8 +79,12 @@ function(func, onstop){
try{ try{
for(var res of func.call(this, ...arguments)){ for(var res of func.call(this, ...arguments)){
if(res === module.STOP){ if(res === module.STOP){
onstop
&& onstop.call(this)
return } return }
if(res instanceof module.STOP){ if(res instanceof module.STOP){
onstop
&& onstop.call(this, res.value)
yield res.value yield res.value
return } return }
yield res } yield res }
@ -105,7 +110,7 @@ function(func, onstop){
return } return }
if(res instanceof module.STOP){ if(res instanceof module.STOP){
onstop onstop
&& onstop.call(this, err.value) && onstop.call(this, res.value)
yield res.value yield res.value
return } return }
yield res } yield res }
@ -127,8 +132,12 @@ function(func, onstop){
var res = await func.call(this, ...arguments) var res = await func.call(this, ...arguments)
// NOTE: this is here for uniformity... // NOTE: this is here for uniformity...
if(res === module.STOP){ if(res === module.STOP){
onstop
&& onstop.call(this)
return } return }
if(res instanceof module.STOP){ if(res instanceof module.STOP){
onstop
&& onstop.call(this, res.value)
return res.value } return res.value }
return res return res
} catch(err){ } catch(err){
@ -147,8 +156,12 @@ function(func, onstop){
var res = func.call(this, ...arguments) var res = func.call(this, ...arguments)
// NOTE: this is here for uniformity... // NOTE: this is here for uniformity...
if(res === module.STOP){ if(res === module.STOP){
onstop
&& onstop.call(this)
return } return }
if(res instanceof module.STOP){ if(res instanceof module.STOP){
onstop
&& onstop.call(this, res.value)
return res.value } return res.value }
return res return res
} catch(err){ } catch(err){