mirror of
https://github.com/flynx/stoppable.js.git
synced 2025-10-28 10:20:10 +00:00
now onstop(..) gets most of the "call context"...
Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
parent
4718d5e443
commit
67c99e06f0
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "ig-stoppable",
|
"name": "ig-stoppable",
|
||||||
"version": "2.0.3",
|
"version": "2.0.4",
|
||||||
"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": {
|
||||||
|
|||||||
33
stoppable.js
33
stoppable.js
@ -67,7 +67,6 @@ 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(
|
||||||
@ -80,22 +79,22 @@ function(func, onstop){
|
|||||||
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
|
||||||
&& onstop.call(this)
|
&& onstop.call(this, res, ...arguments)
|
||||||
return }
|
return }
|
||||||
if(res instanceof module.STOP){
|
if(res instanceof module.STOP){
|
||||||
onstop
|
onstop
|
||||||
&& onstop.call(this, res.value)
|
&& onstop.call(this, res.value, ...arguments)
|
||||||
yield res.value
|
yield res.value
|
||||||
return }
|
return }
|
||||||
yield res }
|
yield res }
|
||||||
} catch(err){
|
} catch(err){
|
||||||
if(err === module.STOP){
|
if(err === module.STOP){
|
||||||
onstop
|
onstop
|
||||||
&& onstop.call(this)
|
&& onstop.call(this, err, ...arguments)
|
||||||
return
|
return
|
||||||
} else if(err instanceof module.STOP){
|
} else if(err instanceof module.STOP){
|
||||||
onstop
|
onstop
|
||||||
&& onstop.call(this, err.value)
|
&& onstop.call(this, err.value, ...arguments)
|
||||||
yield err.value
|
yield err.value
|
||||||
return }
|
return }
|
||||||
throw err } }
|
throw err } }
|
||||||
@ -106,22 +105,22 @@ function(func, onstop){
|
|||||||
for await(var res of func.call(this, ...arguments)){
|
for await(var res of func.call(this, ...arguments)){
|
||||||
if(res === module.STOP){
|
if(res === module.STOP){
|
||||||
onstop
|
onstop
|
||||||
&& onstop.call(this)
|
&& onstop.call(this, res, ...arguments)
|
||||||
return }
|
return }
|
||||||
if(res instanceof module.STOP){
|
if(res instanceof module.STOP){
|
||||||
onstop
|
onstop
|
||||||
&& onstop.call(this, res.value)
|
&& onstop.call(this, res.value, ...arguments)
|
||||||
yield res.value
|
yield res.value
|
||||||
return }
|
return }
|
||||||
yield res }
|
yield res }
|
||||||
} catch(err){
|
} catch(err){
|
||||||
if(err === module.STOP){
|
if(err === module.STOP){
|
||||||
onstop
|
onstop
|
||||||
&& onstop.call(this)
|
&& onstop.call(this, err, ...arguments)
|
||||||
return
|
return
|
||||||
} else if(err instanceof module.STOP){
|
} else if(err instanceof module.STOP){
|
||||||
onstop
|
onstop
|
||||||
&& onstop.call(this, err.value)
|
&& onstop.call(this, err.value, ...arguments)
|
||||||
yield err.value
|
yield err.value
|
||||||
return }
|
return }
|
||||||
throw err } }
|
throw err } }
|
||||||
@ -133,21 +132,21 @@ function(func, onstop){
|
|||||||
// NOTE: this is here for uniformity...
|
// NOTE: this is here for uniformity...
|
||||||
if(res === module.STOP){
|
if(res === module.STOP){
|
||||||
onstop
|
onstop
|
||||||
&& onstop.call(this)
|
&& onstop.call(this, res, ...arguments)
|
||||||
return }
|
return }
|
||||||
if(res instanceof module.STOP){
|
if(res instanceof module.STOP){
|
||||||
onstop
|
onstop
|
||||||
&& onstop.call(this, res.value)
|
&& onstop.call(this, res.value, ...arguments)
|
||||||
return res.value }
|
return res.value }
|
||||||
return res
|
return res
|
||||||
} catch(err){
|
} catch(err){
|
||||||
if(err === module.STOP){
|
if(err === module.STOP){
|
||||||
onstop
|
onstop
|
||||||
&& onstop.call(this)
|
&& onstop.call(this, err, ...arguments)
|
||||||
return
|
return
|
||||||
} else if(err instanceof module.STOP){
|
} else if(err instanceof module.STOP){
|
||||||
onstop
|
onstop
|
||||||
&& onstop.call(this, err.value)
|
&& onstop.call(this, err.value, ...arguments)
|
||||||
return err.value }
|
return err.value }
|
||||||
throw err } }
|
throw err } }
|
||||||
// function...
|
// function...
|
||||||
@ -157,21 +156,21 @@ function(func, onstop){
|
|||||||
// NOTE: this is here for uniformity...
|
// NOTE: this is here for uniformity...
|
||||||
if(res === module.STOP){
|
if(res === module.STOP){
|
||||||
onstop
|
onstop
|
||||||
&& onstop.call(this)
|
&& onstop.call(this, res, ...arguments)
|
||||||
return }
|
return }
|
||||||
if(res instanceof module.STOP){
|
if(res instanceof module.STOP){
|
||||||
onstop
|
onstop
|
||||||
&& onstop.call(this, res.value)
|
&& onstop.call(this, res.value, ...arguments)
|
||||||
return res.value }
|
return res.value }
|
||||||
return res
|
return res
|
||||||
} catch(err){
|
} catch(err){
|
||||||
if(err === module.STOP){
|
if(err === module.STOP){
|
||||||
onstop
|
onstop
|
||||||
&& onstop.call(this)
|
&& onstop.call(this, err, ...arguments)
|
||||||
return
|
return
|
||||||
} else if(err instanceof module.STOP){
|
} else if(err instanceof module.STOP){
|
||||||
onstop
|
onstop
|
||||||
&& onstop.call(this, err.value)
|
&& onstop.call(this, err.value, ...arguments)
|
||||||
return err.value }
|
return err.value }
|
||||||
throw err } },
|
throw err } },
|
||||||
{ toString: function(){
|
{ toString: function(){
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user