tweaking stoppable...

Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
Alex A. Naanou 2022-06-29 11:28:52 +03:00
parent 1944b5ceca
commit ff294074d3

View File

@ -396,8 +396,10 @@ var AsyncGenerator =
module.AsyncGenerator = module.AsyncGenerator =
(async function*(){}).constructor (async function*(){}).constructor
// XXX should we have a generic generator that cand return STOP??? // XXX should we have a generic generator that cand return STOP???
// XXX // XXX
var stoppable = var stoppable =
module.stoppable = module.stoppable =
@ -409,7 +411,17 @@ function(func){
// in sync... // in sync...
function*(){ function*(){
try{ try{
/* XXX should we return STOP???
yield* func.call(this, ...arguments) yield* func.call(this, ...arguments)
/*/
for(var res of func.call(this, ...arguments)){
if(res === STOP){
return }
if(res instanceof STOP){
yield res.value
return }
yield res }
//*/
} catch(err){ } catch(err){
if(err === STOP){ if(err === STOP){
return return
@ -423,7 +435,17 @@ function(func){
// in sync... // in sync...
async function*(){ async function*(){
try{ try{
/* XXX should we return STOP???
yield* func.call(this, ...arguments) yield* func.call(this, ...arguments)
/*/
for(var res of func.call(this, ...arguments)){
if(res === STOP){
return }
if(res instanceof STOP){
yield res.value
return }
yield res }
//*/
} catch(err){ } catch(err){
if(err === STOP){ if(err === STOP){
return return
@ -433,7 +455,16 @@ function(func){
throw err } } throw err } }
: function(){ : function(){
try{ try{
/* XXX should we return STOP???
return func.call(this, ...arguments) return func.call(this, ...arguments)
/*/
var res = func.call(this, ...arguments)
if(res === STOP){
return }
if(res instanceof STOP){
return res.value }
return res
//*/
} catch(err){ } catch(err){
if(err === STOP){ if(err === STOP){
return return