Re: Question about the Main Thread
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