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

Watcher no longer works after server goes down/up #3

Open
charliebecker opened this issue Aug 6, 2016 · 2 comments
Open

Watcher no longer works after server goes down/up #3

charliebecker opened this issue Aug 6, 2016 · 2 comments

Comments

@charliebecker
Copy link

I used your demo messenger app and am having an issue where if the server goes down, the watcher on the client (chat.html) no longer works. I added the following to the server:

// Send a new message to the client every 5 seconds
var i=0;
setInterval(function() {
if(syc.list('messages')) {
var message = {
screenname: 'FROM_SERVER',
content: 'Test #' + i++
};
console.log('Sending message: ' + JSON.stringify(message));
syc.list('messages').push(message);
}
},5000);

When I refresh the client it recovers and displays the new messages no problem, but when I stop and start the server, the client receives the message but the watch no longer works.

I also tried adding a new watch whenever the socket connects on the client by doing the following:

socket.on('connect', function() {
console.log('SOCKET.ON.connect');
Syc.loaded(function () {
Syc.list('messages').forEach(function (message) {
addMessage(message);
});
// Whenever a new message is added to the array,
Syc.watch(Syc.list('messages'), function (change) {
addMessage(change.newValue);
});
});
});

But that didn't fix the issue, the client keeps receiving the changes from the server but the watched 'messages' callback does not get triggered.

Great library, thanks for creating it... it's going to simplify my client/server code drastically, I just need it to be reliable even when the server is brought down.

Charlie

@charliebecker
Copy link
Author

I did a slight modification to the chat.html code, by adding a 0ms timeout before we call Syc.watch and it fixed the problem. Now the it is watching the new id, and not the old one.

socket.on('connect', function() {
console.log('SOCKET.ON.connect');
Syc.loaded(function () {
setTimeout(function() {
Syc.watch(Syc.list('messages'), function (change) {
addMessage(change.newValue);
});
},0);
});
});

I haven't dug into your code enough to know how this could be fixed from within syc, but hopefully it will help others until the code is fixed.

Thanks again,

Charlie

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
@charliebecker and others