• 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: NSPrivateQueueConcurrencyType working outside of performBlock
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: NSPrivateQueueConcurrencyType working outside of performBlock


  • Subject: Re: NSPrivateQueueConcurrencyType working outside of performBlock
  • From: Roland King <email@hidden>
  • Date: Wed, 29 Jul 2015 06:55:24 +0800

>>
>
> performBlockAndWait might work. In my completion handler I have basically:
>
> Context = [self createPrivateContect];
>
> For (I = 1; I < something ; i++)
> {
>    ...do stuff with completetion data from URL...
>
>    ...do stuff with the context...
>
> }
>
> So I need to make sure the context stuff finishes before the for loop goes
> onto the next pass through the loop.
>
>
>

What’s wrong with

	for( i - i ; i < something ; i++ )
	{
		moc.performBlock( {
			… do stuff with completion data
			.. block which does stuff with the context
		} )
	}

nothing says you can only have MOC work in the block

or even

	moc.performBlock(
	{
		for( i - i ; i < something ; i++ )
		{
			… do stuff with completion data
			.. do stuff with the context
		}
	} )

Which is basically your original code just in a performBlock on the MOC’s private thread.


There are other ways too where, if you want to perform the first load of work on one thread and the MOC stuff on the MOC thread, you can do that by putting one iteration in a method or creating a local block which does one iteration with work on one queue, then sends the MOC stuff to the private queue, at the end of the work on the MOC you increment i and if you have another one to do, enqueue the whole thing back on the first thread again.

	int __block i = 1;

	void (^myBlock)() = {
		.. do stuff with completion data
		moc.performBlock( {
			.. do stuff with the context
			if( i++ < something )
				dispatch_async( myOtherQueue, myBlock );
		}
	}

	myBlock()

I’m sure there’s lots more. You can use performBlockAndWait but rarely need to.

All examples typed in mail and I’ve not been using objc for a while so may have my (^) in the wrong place.




_______________________________________________

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


References: 
 >Re: NSPrivateQueueConcurrencyType working outside of performBlock (From: Trygve Inda <email@hidden>)

  • Prev by Date: Re: NSPrivateQueueConcurrencyType working outside of performBlock
  • Next by Date: Re: Codesigning issues
  • Previous by thread: Re: NSPrivateQueueConcurrencyType working outside of performBlock
  • Next by thread: Re: NSPrivateQueueConcurrencyType working outside of performBlock
  • Index(es):
    • Date
    • Thread