From 4718d5e443e66cf3d5847e49b46eaf256330865f Mon Sep 17 00:00:00 2001 From: "Alex A. Naanou" Date: Thu, 29 Dec 2022 02:56:19 +0300 Subject: [PATCH] fix a rushed sloppy update... Signed-off-by: Alex A. Naanou --- package.json | 2 +- stoppable.js | 15 ++++++++++++++- 2 files changed, 15 insertions(+), 2 deletions(-) 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){