Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ensureInBackground + QOS_CLASS_UNSPECIFIED #1286

Merged
merged 2 commits into from
Feb 28, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions Sources/AnyPromise.h
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,13 @@ typedef void (^PMKResolver)(id __nullable) NS_REFINED_FOR_SWIFT;
*/
- (AnyPromise * __nonnull(^ __nonnull)(dispatch_queue_t __nonnull, dispatch_block_t __nonnull))ensureOn NS_REFINED_FOR_SWIFT;

/**
The provided block is executed on the global background queue when the receiver is resolved.

@see ensure
*/
- (AnyPromise * __nonnull(^ __nonnull)(dispatch_block_t __nonnull))ensureInBackground NS_REFINED_FOR_SWIFT;

/**
Wait until the promise is resolved.

Expand Down
6 changes: 6 additions & 0 deletions Sources/AnyPromise.m
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,12 @@ - (id)__d {
};
}

- (AnyPromise *(^)(dispatch_block_t))ensureInBackground {
return ^(dispatch_block_t block) {
return [self->d __ensureOn:dispatch_get_global_queue(QOS_CLASS_UNSPECIFIED, 0) execute:block];
};
}

- (id)wait {
return [d __wait];
}
Expand Down
2 changes: 1 addition & 1 deletion Sources/after.m
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
AnyPromise *PMKAfter(NSTimeInterval duration) {
return [AnyPromise promiseWithResolverBlock:^(PMKResolver resolve) {
dispatch_time_t time = dispatch_time(DISPATCH_TIME_NOW, (int64_t)(duration * NSEC_PER_SEC));
dispatch_after(time, dispatch_get_global_queue(0, 0), ^{
dispatch_after(time, dispatch_get_global_queue(QOS_CLASS_UNSPECIFIED, 0), ^{
resolve(@(duration));
});
}];
Expand Down
2 changes: 1 addition & 1 deletion Sources/dispatch_promise.m
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@
}

AnyPromise *dispatch_promise(id block) {
return dispatch_promise_on(dispatch_get_global_queue(0, 0), block);
return dispatch_promise_on(dispatch_get_global_queue(QOS_CLASS_UNSPECIFIED, 0), block);
}
10 changes: 8 additions & 2 deletions Tests/CoreObjC/AnyPromiseTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

static inline AnyPromise *fulfillLater() {
return [AnyPromise promiseWithResolverBlock:^(PMKResolver resolve) {
dispatch_async(dispatch_get_global_queue(0, 0), ^{
dispatch_async(dispatch_get_global_queue(QOS_CLASS_UNSPECIFIED, 0), ^{
resolve(@1);
});
}];
Expand Down Expand Up @@ -797,7 +797,13 @@ - (void)testInBackground {

- (void)testEnsureOn {
id ex = [self expectationWithDescription:@""];
PMKAfter(0.1).ensureOn(dispatch_get_global_queue(0, 0), ^{ [ex fulfill]; });
PMKAfter(0.1).ensureOn(dispatch_get_global_queue(QOS_CLASS_UNSPECIFIED, 0), ^{ [ex fulfill]; });
[self waitForExpectationsWithTimeout:1 handler:nil];
}

- (void)testEnsureInBackground {
id ex = [self expectationWithDescription:@""];
PMKAfter(0.1).ensureInBackground(^{ [ex fulfill]; });
[self waitForExpectationsWithTimeout:1 handler:nil];
}

Expand Down