promises
promises copied to clipboard
Question regarding implementation
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;
}
- What is the purpose of
dispatch_group_async(FBLPromise.dispatchGroup
? I mean whydispatch_group_async
what the purpose of groupes (I feel it like synchronizes the calls ) - if the queue was asynchronous (not serial by default) what guarantee that
work
will be executed after the calling code