> On Jun 29, 2015, at 10:13 AM, Gavin Eadie <ga...@umich.edu> wrote:
> 
> The problem with the callback to “after” is that “after” is just the 
> continuation of the program and possibly nothing to do with what happens in 
> “fakeSyncrony” ..

Yeah, I don’t think you have any alternative but to restructure your code to 
run asynchronously. Luckily blocks and dispatch queues make it possible to do 
that without having to refactor the code too heavily. There’s a common pattern 
where you change

        - (void) foo {
                A();
                B();
                C();
                }

into

        - (void) foo {
                A();
                dispatch_async(bg_queue, ^{
                        B();
                        dispatch_async(main_queue, ^{
                                C();
                        });
                });
        }

The problem of course is that the semantics of -foo have now changed such that 
the final part of the work (C) doesn’t happen until later, so any caller of 
-foo has to be aware of this, which can require more restructuring. Lather, 
rinse, repeat.

Fun fact: The latest versions of C# have some cool async support that 
essentially do what you’re trying to do here — turn a synchronous call into an 
async one while still leaving the code looking synchronous. It does nasty 
continuation-based stack magic in the compiler to make this work.

—Jens


_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to