Closed duemunk closed 8 years ago
Might already work with:
let block1 = Async.utility {}
let block2 = Async.background {}
block1.wait()
block2.wait()
Async.main {}
@duemunk At least in some code I've been writing waiting on a group was faster than multiple wait calls. My proposal for handling dispatch groups would be to have [dispatch_block_t] argument versions of the static methods that dispatch all provided blocks to the same dispatch group and return a different object/struct more like the one in Async.legacy again with the same methods.
Most of the method behaviours are obvious:
Cancel is the one that is less clear. Should it only cancel the group if it hasn't started at all or should it cancel any blocks that have not yet started. I think the later is actually easier to implement and probably better.
Let me know what you think, I don't want .legacy to have diverging behaviour.
@chriseidhof Not sure if this will get to you but you suggested a GCD wrapper, do you have a view on this.
I think it looks cool. What about being able to compose blocks with return types? e.g.
blockA : A -> B blockB : B -> C
And then you can do Async.start(x).background(blockA).background(blockB). If A doesn't have an input parameter, you could use () instead. Would that make sense?
I'm currently on vacation for two weeks and the hotel wifi is very spotty here in San Francisco. Feel free to discuss without me :)
Enjoy your holiday! I find San Francico lacking good internet slightly ironic but you can concentrate on the sights. If you have time in your trip do visit Yosemite for a couple of days. I haven't tried the OS yet but the scenery in the park is amazing and we saw a couple of bears too.
@josephlord I managed to get to Yosemite. Very nice, but veeery dry :)
Sorry for not getting back to this earlier. Hopefully I can get a look on all your contributions over the holidays.
@chriseidhof Please refer to https://github.com/duemunk/Async/issues/3 for the current work on bringning return types to Async. Spoiler, it's not working yet :)
Refer to branch https://github.com/duemunk/Async/tree/feature/Groups for current work in progress
Sorry to reopen an old discussion, but I'd love this in Async. I've only got one thing in my app using dispatch_group
, but it'd be much simpler to be able to do them with Async.
@harlanhaskins Please feel free to extend Async to support dispatch_group
s. I haven't had the use of groups myself, so I think it would be better for you to make a suggestion.
I've gone on a different direction and added AsyncGroup (see #75). It does not support chaining, which I thought would be confusing with group blocks. It does, however, have support for arbitrary non-GCD blocks.
Thanks @eneko! I think this simplified approach is better, and at least good for now. Hopefully Swift gets better asynchronous support by version 4.0 or 5.0 :)
Wait for multiple blocks to finish
using dispatch_group()