You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

58 lines
1.5 KiB

5 years ago
  1. /**
  2. Copyright 2018 Google Inc. All rights reserved.
  3. Licensed under the Apache License, Version 2.0 (the "License");
  4. you may not use this file except in compliance with the License.
  5. You may obtain a copy of the License at:
  6. http://www.apache.org/licenses/LICENSE-2.0
  7. Unless required by applicable law or agreed to in writing, software
  8. distributed under the License is distributed on an "AS IS" BASIS,
  9. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10. See the License for the specific language governing permissions and
  11. limitations under the License.
  12. */
  13. #import "FBLPromise+Always.h"
  14. #import "FBLPromisePrivate.h"
  15. @implementation FBLPromise (AlwaysAdditions)
  16. - (FBLPromise *)always:(FBLPromiseAlwaysWorkBlock)work {
  17. return [self onQueue:FBLPromise.defaultDispatchQueue always:work];
  18. }
  19. - (FBLPromise *)onQueue:(dispatch_queue_t)queue always:(FBLPromiseAlwaysWorkBlock)work {
  20. NSParameterAssert(queue);
  21. NSParameterAssert(work);
  22. return [self chainOnQueue:queue
  23. chainedFulfill:^id(id value) {
  24. work();
  25. return value;
  26. }
  27. chainedReject:^id(NSError *error) {
  28. work();
  29. return error;
  30. }];
  31. }
  32. @end
  33. @implementation FBLPromise (DotSyntax_AlwaysAdditions)
  34. - (FBLPromise * (^)(FBLPromiseAlwaysWorkBlock))always {
  35. return ^(FBLPromiseAlwaysWorkBlock work) {
  36. return [self always:work];
  37. };
  38. }
  39. - (FBLPromise * (^)(dispatch_queue_t, FBLPromiseAlwaysWorkBlock))alwaysOn {
  40. return ^(dispatch_queue_t queue, FBLPromiseAlwaysWorkBlock work) {
  41. return [self onQueue:queue always:work];
  42. };
  43. }
  44. @end