How to know when a block has been completed

Display Name

Can someone help,

I have a NSMutablearray which contains approx a 1000 data entries.

What i want to do is go though these entries one by one and send them to a server with HTTP request.

However its important that i only send them one at a time, so i have the following pseudo code

for(int i =0; i < array.count; i++)
{
    [ServerLayer ServerUploadRow:[array objectAtIndex:i] : ^void (int ReturnValue, BOOL err){
        if(err == true)
        {
            //Do some local stuff here.
        }
    }];
}

what i ideally want to do is having something like the following

for(int i =0; i < array.count; i++)
{
    //Wait here till i know that we not waiting on a block to complete

    [ServerLayer ServerUploadRow:[array objectAtIndex:i] : ^void (int ReturnValue, BOOL err){
        if(err == true)
        {
            //Do some local stuff here.
            //Signify that we done
        }
    }];
}

the function ServerUploadRow just sends HTTP command.

Thanks

Rob

Assuming that ServerUploadRow runs asynchronously, you can have the request initiate the next request in the completion block of the previous one:

- (void)initiateRequestNumber:(NSInteger)index 
{
    [ServerLayer ServerUploadRow:array[index] : ^(int ReturnValue, BOOL err){
        if (err == true) {
            //Do some local stuff here.
        } else {
            NSInteger nextIndex = index + 1;

            if (nextIndex < array.count) {
                [self initiateRequestNumber:nextIndex];
            } else {
                // do whatever you want now that everything is done
            }
        }
    }];
}

And you'd start this with:

[self initiateRequestNumber:0];

If you can issue these requests concurrently, or better combine all of this in one request, it will be much faster. I'd suggest considering refactoring your web service to enable this, if at all possible. But submitting 1000 network requests sequentially is going to horribly slow (as you'll suffer network latency 1000 times).

この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。

侵害の場合は、連絡してください[email protected]

編集
0

コメントを追加

0

関連記事

分類Dev

How to know if a flutter image has been seen by the user

分類Dev

How do I know if a QuickBlox message has been throttled

分類Dev

How to know if the ESP8266 has been manually reset?

分類Dev

How to know if threading.Condition.wait(timeout) has timed out or has been notified?

分類Dev

How to execute code when ReactJS component has been applied to DOM

分類Dev

How to know all items of a list-view has been viewed in android?

分類Dev

Determining when a socket has been closed on Android

分類Dev

Detect when rotation has completed and move to new Scene

分類Dev

How to proper ommit UnboundLocalError: Local variable '' referenced before assignment when exception has been thrown?

分類Dev

Flutter: How to get a pop value when the original target page has been replaced?

分類Dev

How can I fsck a partition when the device reads as busy (but has been confirmed otherwise)?

分類Dev

How to use gzip if it has not been enabled

分類Dev

In CUDA programming how to understand if the GPU kernel has completed its task?

分類Dev

How to know if a set of threads has finished

分類Dev

How to know if the winform has stopped functioning/responding

分類Dev

I'm getting spurious ("field is required", when field has been set!) validation messages from KendoUI dropdown lists/EditorTemplates - how to solve?

分類Dev

How to know when StreamReader is ready?

分類Dev

FFmpeg returns' Output must be specified' when it has been acknowledged

分類Dev

Change document title when title has been changed by another script

分類Dev

Recovering files when Windows 7 MBR has been corrupted

分類Dev

NameError when trying to use module that has been imported

分類Dev

Connection property has not been initialized when filling a DataSet

分類Dev

Is it possible to tell when /dev/kmsg has been ratelimited?

分類Dev

bash script to execute a command,when RAID rebuilt has been finished

分類Dev

Add a class 'hidden' to my div when cookie has been set

分類Dev

How to know which is the real drive behind the mapped block device?

分類Dev

How to trigger Google Script when a Google Task is marked "completed"

分類Dev

How to check how long a process has been running?

分類Dev

How to check how many topics has been subscribed?

Related 関連記事

  1. 1

    How to know if a flutter image has been seen by the user

  2. 2

    How do I know if a QuickBlox message has been throttled

  3. 3

    How to know if the ESP8266 has been manually reset?

  4. 4

    How to know if threading.Condition.wait(timeout) has timed out or has been notified?

  5. 5

    How to execute code when ReactJS component has been applied to DOM

  6. 6

    How to know all items of a list-view has been viewed in android?

  7. 7

    Determining when a socket has been closed on Android

  8. 8

    Detect when rotation has completed and move to new Scene

  9. 9

    How to proper ommit UnboundLocalError: Local variable '' referenced before assignment when exception has been thrown?

  10. 10

    Flutter: How to get a pop value when the original target page has been replaced?

  11. 11

    How can I fsck a partition when the device reads as busy (but has been confirmed otherwise)?

  12. 12

    How to use gzip if it has not been enabled

  13. 13

    In CUDA programming how to understand if the GPU kernel has completed its task?

  14. 14

    How to know if a set of threads has finished

  15. 15

    How to know if the winform has stopped functioning/responding

  16. 16

    I'm getting spurious ("field is required", when field has been set!) validation messages from KendoUI dropdown lists/EditorTemplates - how to solve?

  17. 17

    How to know when StreamReader is ready?

  18. 18

    FFmpeg returns' Output must be specified' when it has been acknowledged

  19. 19

    Change document title when title has been changed by another script

  20. 20

    Recovering files when Windows 7 MBR has been corrupted

  21. 21

    NameError when trying to use module that has been imported

  22. 22

    Connection property has not been initialized when filling a DataSet

  23. 23

    Is it possible to tell when /dev/kmsg has been ratelimited?

  24. 24

    bash script to execute a command,when RAID rebuilt has been finished

  25. 25

    Add a class 'hidden' to my div when cookie has been set

  26. 26

    How to know which is the real drive behind the mapped block device?

  27. 27

    How to trigger Google Script when a Google Task is marked "completed"

  28. 28

    How to check how long a process has been running?

  29. 29

    How to check how many topics has been subscribed?

ホットタグ

アーカイブ