Backbone listenTo timeout

225 Views Asked by At

I am connected to a web socket and constantly updating my model based on the incoming JSON objects.

Using this coffeesScript code:

    @listenTo @model, 'change', @render

I am listening for every moment that the model is updated and then I render that newly updated model. This works well. However, I would now like to set a timeout so that if the listener doesn't detect a model update after 30 seconds, I can call a different function and update my model with a timeout message. What is the best way set up this timeout?

1

There are 1 best solutions below

0
On

I think you should add callbacks at where you send ajax requests. When you listen to a model's change event, you don't know when the request is sent.

What if you want to add features like auto-refresh? In that scenario 'change' event is listened once but there could be multiple requests that can timeout. These are separated things.