Pause a live query

39 views
Skip to first unread message

Tobin Harris

unread,
Nov 3, 2012, 9:24:24 AM11/3/12
to mobile-c...@googlegroups.com
I want my CouchLiveQuery to be paused when it's not the active screen in a navigation hierarchy, and then resume when the screen is loaded. This is to stop the query running and initiating re-indexing whilst the view is not visible.

Any ideas how to achieve this?

Thanks

Tobin 

Jens Alfke

unread,
Nov 3, 2012, 3:32:26 PM11/3/12
to mobile-c...@googlegroups.com

On Nov 3, 2012, at 6:24 AM, Tobin Harris <to...@engineroomapps.com> wrote:

I want my CouchLiveQuery to be paused when it's not the active screen in a navigation hierarchy, and then resume when the screen is loaded. This is to stop the query running and initiating re-indexing whilst the view is not visible.

Currently the best you can do is to dealloc the query object and re-create it the next time you need it. That’s probably awkward to do if you’ve got KV observers, though.

It would be pretty easy to add support for this to CouchLiveQuery — maybe a .paused property. While paused the object would ignore database-changed notifications except to set a flag remembering that one happened; when resumed, if the flag is set it’ll update immediately. Pull requests welcomed :)

(Even if you don’t implement this, it’d be great if you could file a CouchCocoa issue suggesting it.)

—Jens

Tobin Harris

unread,
Nov 3, 2012, 7:34:45 PM11/3/12
to mobile-c...@googlegroups.com
Thanks jens

The query object was an nstance variable, with state set by user interaction.

I ended up creating a copy of the query using asLiveQuery, an nil-ing the original.. I could then restart that query with correct state when the view appeared again. I'll update the bug db or implement a pause function when I et a mo!

Tobin

Tobin Harris

unread,
Nov 4, 2012, 8:48:23 AM11/4/12
to mobile-c...@googlegroups.com
Have put this on the CouchCocoa issue list for now. I might get to fix it quite soon.


T
Reply all
Reply to author
Forward
0 new messages