google / google/promises

Question regarding implementation

Open
#200 3 comments 0 reactions 0 assignees View on GitHub
Dominant language
Objective-C
Stars
3.8k
Forks
316
PR merge metrics
No merged PRs in 30d

Description

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](https://github.com/google/promises/blob/308ed911c1e83f3063f3810636aa3a507fc48455/Sources/FBLPromises/FBLPromise%2BAsync.m)
```
+ (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

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.