Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Make NSOperation synchronous

I am working on an app that allows an user to create files and folders on the cloud from iPad. When a file is deleted, the app automatically creates a 'Recycle Bin' folder on the cloud and puts that file in it. I have created NSOperationQueue for all the operations i.e. I have separate queue for Folder Creation and a separate queue for File Upload. The problem that I am facing is that, the operation for file upload gets executed before the operation for folder creation is completed and so file doesn't gets uploaded successfully.

Can anyone help me to make the folder creation operation synchronous?

I have tried the following code

[create_folder_queue addOperations:[NSArray arrayWithObject:folderOperation] waitUntilFinished:YES];

but it doesn't execute the operation.

Thanks in advance.

like image 919
Musti Avatar asked Dec 01 '22 00:12

Musti


1 Answers

If you want a synchronous queue, run the -setMaxConcurrentOperationCount: method on your operation queue to set it to 1.

After setting this property, you will only have at most one operation running at a time in the queue, which is more or less the definition of a synchronous queue, where one task only follows after another is complete.

like image 112
Alex Reynolds Avatar answered Dec 05 '22 10:12

Alex Reynolds