-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
Nice way to run on specific queues #1
Comments
Yes, I'll add the choose-a-queue variant, and probably add an For other kinds of "executor" I'll wait for people to propose additions or use cases. |
Wonderful! |
I started to consider the But as you can see above, I committed |
A category of NSOperationQueue seems more flexible than subclassing NSOperation e.g. it accomodates projects that already subclass NSOperation. From my experience using Bolts, one of the most important features was being able to choose the dispatch queue / NSOperationQueue to run a block so being able to do that in PromiseKit would be good. For |
As an additional note, I will make it possible for |
"I will make it possible for then to specify a queue" -->> Max, tell me please, when do you think this feature will be ready and available via CocoaPods? |
As soon as I can figure out how to do it elegantly. I can't really estimate that well, but I really would like to get this in ASAP. |
Okay, thanks. Look forward to it. In the mean time, does current implementation execute each For example:
Explain please how can I know on which thread/queue a block in the chain would be executed? |
There is also There is currently no guarantees about the queue a then runs on, it depends on the implementation of the Promise, it's just currently they all then onto main. Thus to achieve your current goals you can do this for now: somepromise.then(^{
return dispatch_promise(^{
//…
});
}).then(^{
return dispatch_promise(^{
//…
});
}); Not pretty, but works for now. Naturally this will mean the main queue is always used as an intermediate, but that should be fine under most circumstances. Just not ideal. |
Okay, thank you very much for the explanation! |
Perhaps this notation would work? dispatch_queue_t myQueue = dispatch_queue_create(...);
dispatch_promise(^{
return md5(email);
}).thenOn(myQueue, ^(NSString *md5){
return [NSURLConnection GET:@"http://gravatar.com/%@", md5];
}).then(^(UIImage *gravatarImage){
self.imageView.image = gravatarImage;
}); By the way, nice design on the block methods! |
@Zyphrax yes, I like that. |
@mxcl I would suggest to allow set a queue (lets name it For most cases you can specify needed queue only twice (at creation time and at last block) like this:
... or even once (if you it is okay to perform everything on DEFAULT concurrent system queue except last block where you set explicitly MAIN queue) like this:
|
I think the solution should cover at least these cases, in a clear and simple notation:
For option 1: PromiseKit could create the concurrent queue for us, priority argument would be nice. For option 2: PromiseKit should be fed a queue argument, the serial queue is likely used in other parts of the code. For option 3: This is probably were support for NSOperations is necessary to tie actions together. Most people will probably need option 1 in their apps, which is in line with the current implementation. The current implementation however is somewhat vague in terms of which queue is being used. Perhaps .then should always continue on the same queue and simply add a .thenOn (for specific queue) and .thenOnMain or .thenOnUI (calls thenOn with main queue). |
This would mean that all your current examples would have to change the last .then to .thenOnMain. (I'm on my phone at the moment, otherwise I would have created a code example). |
Then has to be mainQueue. Promises are cross-library solutions, and could come from any source. Their behavior has to be consistent, or their utility is reduced. |
Ok, that makes sense. Perhaps use a different method to continue on the same queue (something like .continue)? Or wouldn't that be necessary because you could simply combine it with the first block? |
I'm not sure of an elegant solution. But for me, usually I only need one then block in any particular chain to be in a background queue, so I try to resist new methods without compelling justification. Especially now, when the library is new, and how it will come to be used is not entirely defined. |
In my app I have the following case:
So basically we want to upload the logs and data dump in the background, but during the logs upload we want to show a HUD to the user. The HUD needs to be controlled by the main queue, the two uploads on a serial or concurrent queue. How would you solve that with PromiseKit? |
Would you find the syntax
affecting subsequent calls to Maybe make it so that only the next call to Perhaps Anyway, that's just a quick snack for thought. :) |
@andrebraga the problem here is that if the promise crosses a library boundary you (the user) have no way of knowing what queue the then will execute on. |
Looks good 👍 |
Enabled the skip install option, was causing app archive builds to work poorly.
One of the things that Bolts does pretty well is let you choose a queue to run a block on, while this is manual with PromiseKit. I think it'd be useful to be able to write:
Also Bolts has an "executor" abstraction that runs blocks. Executors might be more general than needed but the default executors are useful to have:
The text was updated successfully, but these errors were encountered: