Skip to content

Question regarding implementation #200

@MikePendo

Description

@MikePendo

Hi
I have looked through the code and was wondering about some parts of it, I would really appreciate if you could share some light
when creating a promise with the following code: link

+ (instancetype)onQueue:(dispatch_queue_t)queue async:(FBLPromiseAsyncWorkBlock)work {
  NSParameterAssert(queue);
  NSParameterAssert(work);

  FBLPromise *promise = [[self alloc] initPending];
  dispatch_group_async(FBLPromise.dispatchGroup, queue, ^{
  work(
        ^(id __nullable value) {
          if ([value isKindOfClass:[FBLPromise class]]) {
            [(FBLPromise *)value observeOnQueue:queue
                fulfill:^(id __nullable value) {
                  [promise fulfill:value];
                }
                reject:^(NSError *error) {
                  [promise reject:error];
                }];
          } else {
            [promise fulfill:value];
          }
        },
        ^(NSError *error) {
          [promise reject:error];
        });
  });
  return promise;
}
  1. What is the purpose of dispatch_group_async(FBLPromise.dispatchGroup? I mean why dispatch_group_async what the purpose of groupes (I feel it like synchronizes the calls )
  2. if the queue was asynchronous (not serial by default) what guarantee that work will be executed after the calling code

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions