简体   繁体   中英

RACSignal: RACSignal code is not executed

Is there a willing soul who could kindly help me with this problem?

This is my scenario:

I need to upload form attachments to the server. So here are the steps:

  1. Retrieve attachment headers from server using Web service.

  2. Match the attachment header with local attachments.

  3. Upload attachments to server.

The Problem:

Using RACSignal I can successfully obtain the attachment headers but when it's time to upload the attachments using NSArray the inner RACSignal of the UploadFormItemAttachments method will not execute.

Additional Information:

This is the code snippet that shows how the RACSignals are handled. BatchSignal is never executed!:

[[[self getFormItemAttachmentHeaders:listName
                          topListItemID:form.topListItemID
                                  form:form
     ] map:^id(NSMutableArray* value) {
        NSArray* attachmentHeaders = [value copy];

        // the code of uploadFormItemAttachments is called but the inner signal does not execute. Why?
        return [self uploadFormItemAttachments:pendingAttachments
                                        attachmentHeaders:attachmentHeaders
                                                     form:form];
        }
      ] subscribeNext:^(id value) {
          // I was expecting the completion result form uploadFormItemAttachments here.
        }
     ];

This the method that iterates over the attachments array and uploads it to the server:

- (RACSignal *)uploadFormItemAttachments:(NSArray*)pendingAttachments attachmentHeaders:(NSArray*)attachmentHeaders form:(SEFSManagedForm*)form
{

  RACSignal* batchSignal = [RACSignal createSignal:^RACDisposable *(id<RACSubscriber> subscriber) {
    [attachmentHeaders enumerateObjectsUsingBlock:^(SEFSFormItemAttachmentHeader* attachmentHeader, NSUInteger idx, BOOL *stop)
     {
       // Look for the local attachment using attachment header from server

       NSPredicate* predicate = [NSPredicate predicateWithFormat:@"identifier = %@", attachmentHeader.document];
       NSArray* foundAttachment = [pendingAttachments filteredArrayUsingPredicate:predicate];

       SEFSManagedAttachment* fullAttachment = foundAttachment[0];

       RACSignal* uploadFormItemAttachmentSignal = [[self uploadFormItemAttachment:fullAttachment
                                                                  attachmentHeader:attachmentHeader                                                            ] map:^id(NSNumber* value) {
         NSMutableArray* valuesArray = [NSMutableArray array];
         [valuesArray addObject:value];
         [valuesArray addObject:attachmentHeader.document];
         RACTuple* tuple = [RACTuple tupleWithObjectsFromArray:valuesArray
                                            convertNullsToNils:YES];
         return tuple;
       }];


       [subscriber sendNext:uploadFormItemAttachmentSignal];
     }];

    [subscriber sendCompleted];
    return nil;
  }];

  return [batchSignal flatten:2];
}

由于uploadFormItemAttachments返回RACSignal ,因此应使用flattenMap代替map

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM