2

continue connloop; throws Syntax Error: Unsyntactic continue.

If I change continue connloop; to continue; , it will run (but ofcourse it will not execute on the outer loop but on the inner one)

Why is this happening, is this deprecated or illegal in nodejs/ecma6?

Please do not recommend me to use function calls instead of labels.

redisSubscriber.on("message", function(channel, event){

event = JSON.parse(event);
const eventPayload = JSON.stringify(event.payload);

 connloop:
  for(let conn in connections){
  conn = connections[conn];
  redisClient.SMEMBERS('connection/'+conn.id+'/subscriptions', (err, subscriptions)=>{

      let intersectedTags = [];
      if(event.address.tags.length > 0 && subscriptions.length > 0){         
        for(let tag in subscriptions){
          tag = subscriptions[tag];

          for(let _tag in event.address.tags){
            _tag = event.address.tags[_tag];
            if(tag == _tag)
              intersectedTags.push(tag);

          }
        }
      }

      let exclusive = false;
      for(let userId in event.address.include){
        userId = event.address.include[userId];
        if(userId == conn.userId){
          exclusive = true;
          break;
        }
      }

      if(intersectedTags.length > 0 || exclusive){
        if(event.address.exclude){
          for(let exclude in event.address.exclude){
            exclude = event.address.exclude[exclude];
            if(exclude == conn.userId){
              continue connloop;
            }
          }
        }
        const browserEvent = {tags: intersectedTags, notification: eventPayload, exclusive};
        conn.write(JSON.stringify(browserEvent));
      }
  })
} });
0

2 Answers 2

2

Using continue label out of closure function is unsyntactic, because of difference scope with continue statement and label connloop:

// continue statement in anonymous function
redisClient.SMEMBERS('connection/'+conn.id+'/subscriptions', (err, subscriptions)=>{

follow codes should be OK with same scope:

redisSubscriber.on("message", function(channel, event){

connloop:
    for(let conn in connections){
        // more codes ...
        for(let exclude in event.address.exclude){
            exclude = event.address.exclude[exclude];
            if(exclude == conn.userId){
               continue connloop;
            }
        }
    }
});
2

continue is not valid across function boundaries. You put the continue inside a function, trying to jump to a position outside the function.

It also doesn't make sense to have a continue there since redisClient.SMEMBERS is most likely an asynchronous operation, so the loop already terminated by the time the callback is called.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.