• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Synchronous method: How to "wait" for Notification to occur?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Synchronous method: How to "wait" for Notification to occur?


  • Subject: Re: Synchronous method: How to "wait" for Notification to occur?
  • From: Andreas Mayer <email@hidden>
  • Date: Fri, 22 Aug 2003 00:53:11 +0200

Am Donnerstag, 21.08.03 um 21:26 Uhr schrieb Rolf:

What's the most elegant way for the method to "wait" for the Notification ? The main RunLoop must be kept active, and the "wait" must not hog CPU time by continually checking if the Notification has arrived. Any good ideas ?

Well, I'm not sure if it's the most elegant solution, but it seems to fit your requirements:

- start a second thread for your synchronous method: [NSThread detachNewThreadSelector:@selector(<yourSynchronousMethod>) toTarget:<yourTarget> withObject:<someParameter>]

- inside that method set a lock with [lock lockBeforeDate:[NSDate dateWithTimeIntervalSinceNow:1.0]] (will wait at most 1 second for the lock to get removed)

- register some object to receive the notification and [lock unlock] the above lock when it's called


bye. Andreas.
_______________________________________________
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.

References: 
 >Synchronous method: How to "wait" for Notification to occur? (From: Rolf <email@hidden>)

  • Prev by Date: Re: Ignoring windowWillClose on app termination
  • Next by Date: Re: How to get NSColorPanel's target?
  • Previous by thread: Synchronous method: How to "wait" for Notification to occur?
  • Next by thread: Re: Synchronous method: How to "wait" for Notification to occur?
  • Index(es):
    • Date
    • Thread