Re: Async AppleScript Commands
Re: Async AppleScript Commands
- Subject: Re: Async AppleScript Commands
- From: Nick Zitzmann <email@hidden>
- Date: Thu, 18 Sep 2003 12:32:00 -0700
On Thursday, September 18, 2003, at 11:31 AM, Michael Robinette wrote:
I'm adding scripting support to my app and it's working well. One of
the events I handle invokes an async transaction in my app, but I want
it to return the result of the transaction.
Is there a good way to queue the script command until the async
transaction is done? or do I have to do it myself?
One way of doing this is to use a lock to block further execution until
the transaction is finished, like this... (note: written in Mail,
untested, use at your own risk)
With these class members:
id theResult;
NSLock *someLock;
- (id)performSomeImplementation:(NSScriptCommand *)command
{
[self doSomething:[command evaludatedArguments]];
[someLock lock]; // execution stops here until someLock is
unlocked...
[someLock unlock];
return theResult;
}
- (void)doSomething:(NSDictionary *)args
{
[someLock lock];
[NSThread detachNewThreadSelector:@selector(threadedDoSomething:)
toTarget:self withObject:args];
}
- (void)threadedDoSomething:(NSDictionary *)args
{
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
// do your work here...
theResult = [someObject someValue];
[someLock unlock]; // unblock execution when done
[pool release];
}
Nick Zitzmann
AIM/iChat: dragonsdontsleep
Check out my software page:
http://seiryu.home.comcast.net/
"I have always wished that my computer would be as easy to use as my
telephone. My wish has come true. I no longer know how to use my
telephone." - Bjarne Stroustrup
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.