Tuesday, September 26, 2017

#1 2012-03-08 04:28:52 pm

From:: Amish Country, Lancaster, PA
Registered: 2004-06-23
Posts: 416

Will OBJ-C wait for long ASOC events?

I was going to build an app in Objective-C, but I need to have some specific ASOC components. And some of these actions are going to take a long time, like 3-20 seconds.
Will Objective-C "wait" for replies to come back from a script?

Like if I say

NSString *aResult = [asocScripts doSomeLongEvent:parameter];

will it wait for aResult to be something? Or will it assume nil/null or failed function after X seconds?
I don't want to start down this road if it would be better off in a straight script because of the application's delays (Adobe illustrator functions to be specific).

Scripts for InDesign: http://chris.paveglio.com
ASOC & Cocoa, specializing in InDesign, Photoshop, Ai, FileMaker



#2 2012-03-08 04:53:47 pm

From:: St. Gallen, Switzerland
Registered: 2006-10-21
Posts: 11481

Re: Will OBJ-C wait for long ASOC events?

Unlike single threaded AppleScript the Objective-C runtime works quite completely different, because you're be able to perform tasks asynchronously on multiple threads.

The big advantage is: there is no need for those creepy AppleScript wait loops which are very expensive.
The Objective-C way is to use notifications or protocols / delegates to inform the main task about the several states of the child task, those protocol methods appear often like

- (BOOL)shouldDoSomething:(id)sender // the boolean value indicates to allow/deny the task
- (void)willDoSomething:(id)sender // will be called before starting the task
- (void)didSomething;(id)sender // will be called after finishing the task

notifications work similarly, in an ASOC environment I guess notifications are preferable

Last edited by StefanK (2012-03-08 04:54:55 pm)





#3 2012-03-08 05:56:21 pm

DJ Bazzie Wazzie
From:: the Netherlands
Registered: 2004-10-20
Posts: 2710

Re: Will OBJ-C wait for long ASOC events?

SuperMacGuy wrote:

Like if I say
NSString *aResult = [asocScripts doSomeLongEvent:parameter];
will it wait for aResult to be something?

Yes... it waits for the method doSomeLongEvents to be finished like any other Objective-C method will wait for a method to be finished before continuing. Doesn't have anything to do with AppleScript directly it is simply following the rules of Objective-C.



#4 2012-03-08 05:57:11 pm

Shane Stanley
From:: Australia
Registered: 2002-12-07
Posts: 5138

Re: Will OBJ-C wait for long ASOC events?

As Stefan says, you can use separate threads, but a lot of AS stuff needs to run on the main thread, as does your UI. There's no risk of timeout, so much as frozen UI. I usually just sprinkle the AS code with fordEvent() from Myriad Helpers, and it works fine. Some of the Illustrator examples I call take a couple of minutes to run.

Shane Stanley <sstanley@myriad-com.com.au>



Board footer

Powered by FluxBB

RSS (new topics) RSS (active topics)