Provide proper main thread handling for Apple frameworks

Idea created by monkeybreadsoftware on Nov 25, 2015
    Active
    Score19

    Plugin code on Server (both script process and web direct process) may run code in Objective-C.

    That works fine currently, except if some framework part from Apple's code relays on using the main thread.


    Especially functions like performSelectorOnMainThread or simply dispatch_async with main thread.

    Those don't work.

     

    It would help if you guys in your server code add a few lines.

    Before your main loop, initialize some Cocoa things.

     

    Code may be as easy as calling this three functions on the right place:

     

    NSAutoreleasePool *pool = nil;

     

     

    void CocoaInit()

    {

      pool = [[NSAutoreleasePool alloc] init];

       

        // access to init

        [NSApplication sharedApplication];

    }

     

     

    void CocoaIdle()

    {

      // clean memory

      [pool release];

      pool = [[NSAutoreleasePool alloc] init];

     

      // process events for this thread

        [[NSRunLoop currentRunLoop] runUntilDate:NULL];  

    }

     

     

    void CocoaIdleShutdown()

    {

        [pool release];

        pool = nil;

    }

     

    So while server initializes, call CocoaInit. While server runs, call on main thread regularly CocoaIdle and on the end you can call CocoaIdleShutdown when server shuts down.

     

    Having a working runloop on main thread may help to get some thing working.