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

Feature request: callback for when all everyone.now.methods have executed #49

Closed
tommedema opened this issue Apr 13, 2011 · 6 comments
Closed

Comments

@tommedema
Copy link

I'm in this situation: I have an incoming stream and receive a chunk. I wish to send this chunk to all now.js clients, but need to pause the stream until all clients have received the chunk.

I can do something like this:

client:

    now.receiveFileChunk = function(id, chunk, cb) {
         //on success
         cb();
    };

and on the server:

 clientsCount = //somehow get ammount of clients here (is this possible?)
 receivedCount = 0;

 stream.pause();
 everyone.now.receiveFileChunk(id, chunk, function() {
      receivedCount++;
      if (receivedCount == clientsCount) stream.resume();
 });

But:

  1. I do not know if it is even possible to get the amount of clients connected
  2. This does not seem like a proper solution

I'm not 100% sure, but it might be a good idea to add a callback to remote function calls for when all clients have received this method. I'm not sure of the implications and overhead involved though...

@ericz
Copy link
Contributor

ericz commented Apr 14, 2011

So right now if you do this, the callback you pass in will be called once for each client, in that client's this.now context.

To get the amount of clients connected you can do what you're doing now. We may add a client count feature so you can easily get the number of clients in a group.

Providing a callback (that runs once) when all callbacks have completed is easy to do, internally it would have to be a counter kind of like what you have now. The difficulty lies in the syntax. Not sure how you would pass this callback in during a remote function call on a group

@tommedema
Copy link
Author

@ericz, at the moment I am not doing this because I cannot get the max count. How would I achieve this functionality now?

@ericz
Copy link
Contributor

ericz commented Apr 14, 2011

Oh duhh. My bad you're right you don't have the max. I'll see if its easy to expose a way a count and get back to you

@ericz
Copy link
Contributor

ericz commented Apr 14, 2011

Ok this now exists in the master on github.

Simply do everyone.count or somegroup.count to get the number of users at the time. Make sure you are careful as its possible that the remote call does not return before the usercount changes.

This is an undocumented feature and the api for this will probably change in the future

@ericz ericz closed this as completed Apr 14, 2011
@tommedema
Copy link
Author

@ericz, thanks. Should a new issue be created such as "document group.count and improve API" or do you have an internal ToDo?

Just figured that it should not be forgotten

@ericz
Copy link
Contributor

ericz commented Apr 14, 2011

I have an internal todo already so no issue is necessary, thanks!

On Thu, Apr 14, 2011 at 9:39 AM, tommedema
reply@reply.github.com
wrote:

@ericz, thanks. Should a new issue be created such as "document group.count and improve API" or do you have an internal ToDo?

Just figured that it should not be forgotten

Reply to this email directly or view it on GitHub:
#49 (comment)

510-691-3951
EECS Student at UC Berkeley
http://ericzhang.com

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

2 participants