Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multiple notifications in parrallel #7

Open
alexislg2 opened this issue May 20, 2015 · 4 comments
Open

Multiple notifications in parrallel #7

alexislg2 opened this issue May 20, 2015 · 4 comments

Comments

@alexislg2
Copy link

Hey folks,
I have a strange behaviour. Sometimes I send multiple notifications in parrallel. It means that I call gcm.send() multiple times. I know I could use an array of reg ID instead but it messages are not the same.

Everything works fine except when there is one error in one of the notifications. For example when one of the recepient has an expired reg Id, I receive the NotRegistered error. My problem is that I get this error for all the other notifications sent at the same time whereas there should be no error for the other recipients. This is strange

@mamaral
Copy link

mamaral commented Jul 13, 2016

+1

@mamaral
Copy link

mamaral commented Jul 13, 2016

I'm not a node js guy, but it appears to me this is probably due to there being n listeners created when you send n requests in a loop, and if one hits the error case it emits the sent event with that error and ALL of those n listeners are listening for it, so they ALL handle the error event.

That explains why if you send n notifications and 1 fails, you get n callbacks with that error.

@Neamar
Copy link

Neamar commented Nov 30, 2017

Yeah, when you look at the code it uses if (cb) this.once('sent', cb);, so if you send multiple notifications in parallel using the same object it will only notify one cb :\

@Neamar
Copy link

Neamar commented Nov 30, 2017

Fix: create a new GCM object everytime you need to send something in parallel.
Alternative fix (require changes in the library): edit code to remove calls to self.emit('sent', ...) by direct calls to cb().

@h2soft I can send a PR, will you merge it and publish to npm?

Neamar added a commit to Neamar/node-gcm that referenced this issue Nov 30, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants