now onstop(..) gets most of the "call context"...

Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
Alex A. Naanou 2022-12-29 03:01:13 +03:00
parent 4718d5e443
commit 67c99e06f0
2 changed files with 17 additions and 18 deletions

View File

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

View File

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