Brian wrote:

Solutions: Haven't been investigated but clearly what is needed is some way to determine if calls sending messages to the Editor are still in progress before allowing the "Done" code to execute. IIRC, some of the GCD calls might have callbacks for this purpose. I could force the "Done" code to wait an extra second to make sure all the threads complete but I'm hoping that approach is unnecessary.

I don't know if any of you are using GCD/threads but it adds a whole new dimension to the programming. Please share your solution thoughts.

Research indicates a group dispatch queue is a potential solution. The tasks are still started asynchronously but they are associated with a group ( which is created with:  dispatch_group_create() ). There is a way ( using a notify group ) to start a task when all the tasks in a group have completed. In FBtoC's case the groups to complete would be the translation and error reporting and the task started via the notify would be the code sending "Done" to the Editor. I have a simple example below but still have to apply this to FBtoC. I'll report back for any still interested.

void DoThis() {
    dispatch_queue_t queue = dispatch_get_global_queue(0,0);
    dispatch_group_t group = dispatch_group_create();

    

    

    dispatch_group_async(group,queue,^{
        for ( int i=0 ; i < 10; i++) {
            NSLog(@"Block 1 loop: %d",i);
        }
        NSLog(@"Block 1 loop end");
    });

    

    dispatch_group_notify(group,queue,^{
        NSLog(@"Final block is executed last after 1 and 2");
    });

    

    dispatch_group_async(group,queue,^{
        for ( int i=0 ; i < 10; i++) {
            NSLog(@"Block 2 loop: %d",i);
        }
        NSLog(@"Block 2 loop end");
    });

    

}

int main(int argc, const char * argv[]) {
    DoThis();
    RunApplicationEventLoop();
}

Here is the output:

2017-03-13 13:31:15.823 TestDispatchGroupII[3537:718658] Block 1 loop: 0
2017-03-13 13:31:15.823 TestDispatchGroupII[3537:718659] Block 2 loop: 0
2017-03-13 13:31:15.825 TestDispatchGroupII[3537:718658] Block 1 loop: 1
2017-03-13 13:31:15.825 TestDispatchGroupII[3537:718659] Block 2 loop: 1
2017-03-13 13:31:15.825 TestDispatchGroupII[3537:718658] Block 1 loop: 2
2017-03-13 13:31:15.825 TestDispatchGroupII[3537:718659] Block 2 loop: 2
2017-03-13 13:31:15.825 TestDispatchGroupII[3537:718658] Block 1 loop: 3
2017-03-13 13:31:15.825 TestDispatchGroupII[3537:718659] Block 2 loop: 3
2017-03-13 13:31:15.825 TestDispatchGroupII[3537:718658] Block 1 loop: 4
2017-03-13 13:31:15.825 TestDispatchGroupII[3537:718659] Block 2 loop: 4
2017-03-13 13:31:15.825 TestDispatchGroupII[3537:718658] Block 1 loop: 5
2017-03-13 13:31:15.825 TestDispatchGroupII[3537:718659] Block 2 loop: 5
2017-03-13 13:31:15.825 TestDispatchGroupII[3537:718658] Block 1 loop: 6
2017-03-13 13:31:15.825 TestDispatchGroupII[3537:718659] Block 2 loop: 6
2017-03-13 13:31:15.825 TestDispatchGroupII[3537:718658] Block 1 loop: 7
2017-03-13 13:31:15.825 TestDispatchGroupII[3537:718659] Block 2 loop: 7
2017-03-13 13:31:15.825 TestDispatchGroupII[3537:718658] Block 1 loop: 8
2017-03-13 13:31:15.825 TestDispatchGroupII[3537:718659] Block 2 loop: 8
2017-03-13 13:31:15.826 TestDispatchGroupII[3537:718658] Block 1 loop: 9
2017-03-13 13:31:15.826 TestDispatchGroupII[3537:718659] Block 2 loop: 9
2017-03-13 13:31:15.826 TestDispatchGroupII[3537:718658] Block 1 loop end
2017-03-13 13:31:15.826 TestDispatchGroupII[3537:718659] Block 2 loop end
2017-03-13 13:31:15.826 TestDispatchGroupII[3537:718658] Final block is executed last after 1 and 2



--
To unsubscribe, send ANY message to: futurebasic-unsubscribe@... To access the list archives, go to: http://freegroups.net/groups/futurebasic/