mozilla/fireplace — pull request #111 by muffinresearch (2013-05-13 11:26:47+00:00)
Title: Fix this value in finish

It occurred to me that the `this` context would be incorrect due to the `setTimeout` defaulting `this` to `window`. This branch fixes that.

In looking at this I re-visited the previous call to `finish` without `setTimeout` and found that calling `finish` directly wasn't actually working as expected in any case. So the setting of `get` etc to `null` wasn't actually taking place because `this` was set to window in that case too. Fixing `this` to be the pool object and calling `finish` directly breaks the pool because the pool closes after the first request and the next `get` is `null`.

Whilst this `setTimeout` workaround appears to work for now - I think there's a need to possibly refactor how the pool is used because ideally it should be possible to have the pool close when all requests are done without any need to use `setTimeout`.

Probably to do that the requests would need to be run *after* they've all been added to the pool rather than running each one as it happens as this is what caused the problem where a request resolves before the next one has even been added to the pool.