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

Add queue method to CBLDatabase to run Asynchronous workloads #21

Closed
rismay opened this issue Mar 15, 2013 · 3 comments
Closed

Add queue method to CBLDatabase to run Asynchronous workloads #21

rismay opened this issue Mar 15, 2013 · 3 comments

Comments

@rismay
Copy link

rismay commented Mar 15, 2013

Currently, you need to create a queue or a thread of your own to run CBL workloads in the background. CBL_Server has a queue method which allows you to perform asynchronous workloads. To solve this problem and keep CBL_Server private, add a queue method to CBLDatabase which then accesses it's private manager and server to queue the block of work.

@snej
Copy link
Contributor

snej commented Mar 21, 2013

The danger of this is that it'd be really easy to misuse. The block has to use the CBL objects running on the background/server thread, not the ones being used by the main code. For example, this would be bad news:

[db dispatch_async: ^{[db compact];}

because it'd be calling db on the wrong thread. Instead you need something like:

[db dispatch_async: ^(CBLDatabase *bgdb) {[bgdb compact];}

but you only need to screw up once and use db instead of bgdb in the block to cause an error. (And it's an error that's likely not to cause any overt trouble most of the time, but occasionally crash or screw things up in mysterious ways.)

@snej
Copy link
Contributor

snej commented Mar 23, 2013

Added a -tellDatabaseNamed:to: method to CBLManager in a commit today.

@snej snej closed this as completed Mar 23, 2013
@rismay
Copy link
Author

rismay commented Mar 23, 2013

This solved my problem exactly. The CBL_Server code isn't hard to duplicate and I could have compiled a modified version from source. However, I think it's important to be able to run async workloads without having to spawn another thread or run a modified version of the official repository. Thanks!

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