promises icon indicating copy to clipboard operation
promises copied to clipboard

Question regarding implementation

Open MikePendo opened this issue 1 year ago • 3 comments

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

MikePendo avatar Dec 26 '22 15:12 MikePendo