diff --git a/package.json b/package.json index 61f3c46..89c8101 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "ig-stoppable", - "version": "2.0.2", + "version": "2.0.3", "description": "Utility library implementing tooling to make stoppable functions...", "main": "stoppable.js", "scripts": { diff --git a/stoppable.js b/stoppable.js index ae9e454..6306859 100644 --- a/stoppable.js +++ b/stoppable.js @@ -67,6 +67,7 @@ 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( @@ -78,8 +79,12 @@ function(func, onstop){ try{ for(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, res.value) yield res.value return } yield res } @@ -105,7 +110,7 @@ function(func, onstop){ return } if(res instanceof module.STOP){ onstop - && onstop.call(this, err.value) + && onstop.call(this, res.value) yield res.value return } yield res } @@ -127,8 +132,12 @@ function(func, onstop){ var res = await func.call(this, ...arguments) // NOTE: this is here for uniformity... if(res === module.STOP){ + onstop + && onstop.call(this) return } if(res instanceof module.STOP){ + onstop + && onstop.call(this, res.value) return res.value } return res } catch(err){ @@ -147,8 +156,12 @@ function(func, onstop){ var res = func.call(this, ...arguments) // NOTE: this is here for uniformity... if(res === module.STOP){ + onstop + && onstop.call(this) return } if(res instanceof module.STOP){ + onstop + && onstop.call(this, res.value) return res.value } return res } catch(err){