mirror of
https://github.com/flynx/stoppable.js.git
synced 2025-10-28 10:20:10 +00:00
added onstop(..) callback...
Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
parent
cf15e7c628
commit
b47ebfbdc6
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "ig-stoppable",
|
||||
"version": "2.0.1",
|
||||
"version": "2.0.2",
|
||||
"description": "Utility library implementing tooling to make stoppable functions...",
|
||||
"main": "stoppable.js",
|
||||
"scripts": {
|
||||
|
||||
22
stoppable.js
22
stoppable.js
@ -68,7 +68,7 @@ var AsyncGenerator =
|
||||
// NOTE: this repeats the same code at lest twice, not sure yet how to avoid
|
||||
// this...
|
||||
module =
|
||||
function(func){
|
||||
function(func, onstop){
|
||||
return Object.assign(
|
||||
// NOTE: the below implementations are almost the same, the main
|
||||
// differences being the respective generator/async mechanics...
|
||||
@ -85,8 +85,12 @@ function(func){
|
||||
yield res }
|
||||
} catch(err){
|
||||
if(err === module.STOP){
|
||||
onstop
|
||||
&& onstop.call(this)
|
||||
return
|
||||
} else if(err instanceof module.STOP){
|
||||
onstop
|
||||
&& onstop.call(this, err.value)
|
||||
yield err.value
|
||||
return }
|
||||
throw err } }
|
||||
@ -96,15 +100,23 @@ function(func){
|
||||
try{
|
||||
for await(var res of func.call(this, ...arguments)){
|
||||
if(res === module.STOP){
|
||||
onstop
|
||||
&& onstop.call(this)
|
||||
return }
|
||||
if(res instanceof module.STOP){
|
||||
onstop
|
||||
&& onstop.call(this, err.value)
|
||||
yield res.value
|
||||
return }
|
||||
yield res }
|
||||
} catch(err){
|
||||
if(err === module.STOP){
|
||||
onstop
|
||||
&& onstop.call(this)
|
||||
return
|
||||
} else if(err instanceof module.STOP){
|
||||
onstop
|
||||
&& onstop.call(this, err.value)
|
||||
yield err.value
|
||||
return }
|
||||
throw err } }
|
||||
@ -121,8 +133,12 @@ function(func){
|
||||
return res
|
||||
} catch(err){
|
||||
if(err === module.STOP){
|
||||
onstop
|
||||
&& onstop.call(this)
|
||||
return
|
||||
} else if(err instanceof module.STOP){
|
||||
onstop
|
||||
&& onstop.call(this, err.value)
|
||||
return err.value }
|
||||
throw err } }
|
||||
// function...
|
||||
@ -137,8 +153,12 @@ function(func){
|
||||
return res
|
||||
} catch(err){
|
||||
if(err === module.STOP){
|
||||
onstop
|
||||
&& onstop.call(this)
|
||||
return
|
||||
} else if(err instanceof module.STOP){
|
||||
onstop
|
||||
&& onstop.call(this, err.value)
|
||||
return err.value }
|
||||
throw err } },
|
||||
{ toString: function(){
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user