• 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: Question about the Main Thread
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Question about the Main Thread


  • Subject: Re: Question about the Main Thread
  • From: Charles Srstka <email@hidden>
  • Date: Tue, 25 Apr 2017 16:37:49 -0500

> On Apr 25, 2017, at 9:51 AM, Dave <email@hidden> wrote:
>
> Mac Project.
>
> Hi All,
>
> I’m using performSelector: withObject: afterDelay: in order to postpone further processing until after the current method/run loop as expired, this puts the request at the End of the Queue, my question is, is there anyway of putting it at the head of the Queue so it gets processing before other requests?
>
> All the Best
> Dave

Consider using NSOperationQueue (OperationQueue if you’re using Swift) instead of performSelector:withObject:afterDelay:, and have a look at the queuePriority property on Operation/NSOperation. The following code:

> import Foundation
>
> let op1 = BlockOperation {
> 	print("op1")
> }
>
> let op2 = BlockOperation {
> 	print("op2")
> }
>
> let quitOp = BlockOperation {
> 	exit(0)
> }
>
> quitOp.addDependency(op1)
> quitOp.addDependency(op2)
>
> op1.queuePriority = .veryLow
> op2.queuePriority = .veryHigh
>
> OperationQueue.main.addOperations([op1, op2, quitOp], waitUntilFinished: false)
>
> RunLoop.main.run()

outputs:

> op2
> op1

This shouldn’t be taken as a guarantee, but it does make it more likely that your operation will be executed before others.

Charles

_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

  • Follow-Ups:
    • Re: Question about the Main Thread
      • From: Charles Srstka <email@hidden>
References: 
 >Help Indexing (From: "Frank D. Engel, Jr." <email@hidden>)
 >Question about the Main Thread (From: Dave <email@hidden>)

  • Prev by Date: Repository of older (outdated) PDF Guides?
  • Next by Date: Re: Question about the Main Thread
  • Previous by thread: Re: Question about the Main Thread
  • Next by thread: Re: Question about the Main Thread
  • Index(es):
    • Date
    • Thread