diff --git a/PINFuture/Classes/Categories/NSURLSession+PINFuture.h b/PINFuture/Classes/Categories/NSURLSession+PINFuture.h index fdcdd8c..88dd0da 100644 --- a/PINFuture/Classes/Categories/NSURLSession+PINFuture.h +++ b/PINFuture/Classes/Categories/NSURLSession+PINFuture.h @@ -9,8 +9,7 @@ #import #import -#import "PINNSURLSessionDataTaskAndResult.h" -#import "PINFuture.h" +#import NS_ASSUME_NONNULL_BEGIN diff --git a/PINFuture/Classes/Categories/NSURLSession+PINFuture.m b/PINFuture/Classes/Categories/NSURLSession+PINFuture.m index 9b70aaf..312d04c 100644 --- a/PINFuture/Classes/Categories/NSURLSession+PINFuture.m +++ b/PINFuture/Classes/Categories/NSURLSession+PINFuture.m @@ -7,6 +7,7 @@ // #import "NSURLSession+PINFuture.h" +#import "PINFutureDefinition.h" NS_ASSUME_NONNULL_BEGIN diff --git a/PINFuture/Classes/Categories/PHImageManager+PINFuture.h b/PINFuture/Classes/Categories/PHImageManager+PINFuture.h index cedfd2b..ff3f652 100644 --- a/PINFuture/Classes/Categories/PHImageManager+PINFuture.h +++ b/PINFuture/Classes/Categories/PHImageManager+PINFuture.h @@ -6,11 +6,10 @@ // Copyright © 2016 Pinterest. All rights reserved. // -#import #import -#import "PINFuture.h" -#import "PINPHImageManagerImageDataResult.h" +#import +#import NS_ASSUME_NONNULL_BEGIN diff --git a/PINFuture/Classes/Categories/PINNSURLSessionDataTaskAndResult.h b/PINFuture/Classes/Categories/PINNSURLSessionDataTaskAndResult.h index b80bd16..14735eb 100644 --- a/PINFuture/Classes/Categories/PINNSURLSessionDataTaskAndResult.h +++ b/PINFuture/Classes/Categories/PINNSURLSessionDataTaskAndResult.h @@ -6,10 +6,8 @@ // // -#import - -#import "PINFuture.h" -#import "PINNSURLSessionDataTaskResult.h" +#import +#import NS_ASSUME_NONNULL_BEGIN diff --git a/PINFuture/Classes/PINCancelToken.h b/PINFuture/Classes/PINCancelToken.h index bbadf86..37fb1a9 100644 --- a/PINFuture/Classes/PINCancelToken.h +++ b/PINFuture/Classes/PINCancelToken.h @@ -4,7 +4,7 @@ #import -#import "PINExecutor.h" +#import typedef dispatch_block_t PINCancellationBlock; diff --git a/PINFuture/Classes/PINFuture+ChainSideEffect.h b/PINFuture/Classes/PINFuture+ChainSideEffect.h index e57735e..be6a67c 100644 --- a/PINFuture/Classes/PINFuture+ChainSideEffect.h +++ b/PINFuture/Classes/PINFuture+ChainSideEffect.h @@ -6,9 +6,8 @@ // Copyright (c) 2017 Pinterest. All rights reserved. // -#import - -#import "PINFuture.h" +#import +#import NS_ASSUME_NONNULL_BEGIN diff --git a/PINFuture/Classes/PINFuture+Completion.h b/PINFuture/Classes/PINFuture+Completion.h index 58ad1cc..d1fda3c 100644 --- a/PINFuture/Classes/PINFuture+Completion.h +++ b/PINFuture/Classes/PINFuture+Completion.h @@ -6,9 +6,7 @@ // Copyright (c) 2017 Pinterest. All rights reserved. // -#import - -#import "PINFuture.h" +#import NS_ASSUME_NONNULL_BEGIN diff --git a/PINFuture/Classes/PINFuture+Delay.h b/PINFuture/Classes/PINFuture+Delay.h index fbff483..822ec90 100644 --- a/PINFuture/Classes/PINFuture+Delay.h +++ b/PINFuture/Classes/PINFuture+Delay.h @@ -5,9 +5,7 @@ // Created by Chris Danford on 4/16/18. // -#import "PINFuture.h" - -#import "PINFuture+MapToValue.h" +#import NS_ASSUME_NONNULL_BEGIN diff --git a/PINFuture/Classes/PINFuture+Dispatch.h b/PINFuture/Classes/PINFuture+Dispatch.h index ec474ca..596ae0e 100644 --- a/PINFuture/Classes/PINFuture+Dispatch.h +++ b/PINFuture/Classes/PINFuture+Dispatch.h @@ -6,7 +6,8 @@ // Copyright (c) 2016 Pinterest. All rights reserved. // -#import "PINFuture.h" +#import +#import NS_ASSUME_NONNULL_BEGIN diff --git a/PINFuture/Classes/PINFuture+FlatMapError.h b/PINFuture/Classes/PINFuture+FlatMapError.h index 4a93655..efcb117 100644 --- a/PINFuture/Classes/PINFuture+FlatMapError.h +++ b/PINFuture/Classes/PINFuture+FlatMapError.h @@ -6,7 +6,8 @@ // Copyright (c) 2016 Pinterest. All rights reserved. // -#import "PINFuture.h" +#import +#import @interface PINFuture (FlatMapError) diff --git a/PINFuture/Classes/PINFuture+GatherAll.h b/PINFuture/Classes/PINFuture+GatherAll.h index 6c5de81..880d301 100644 --- a/PINFuture/Classes/PINFuture+GatherAll.h +++ b/PINFuture/Classes/PINFuture+GatherAll.h @@ -7,7 +7,6 @@ // #import -#import "PINFuture.h" NS_ASSUME_NONNULL_BEGIN diff --git a/PINFuture/Classes/PINFuture+GatherSome.h b/PINFuture/Classes/PINFuture+GatherSome.h index 5faa215..dc68372 100644 --- a/PINFuture/Classes/PINFuture+GatherSome.h +++ b/PINFuture/Classes/PINFuture+GatherSome.h @@ -6,8 +6,8 @@ // // -#import -#import "PINFuture.h" +#import +#import NS_ASSUME_NONNULL_BEGIN diff --git a/PINFuture/Classes/PINFuture+GatherSome.m b/PINFuture/Classes/PINFuture+GatherSome.m index 2f092b9..37e7f44 100644 --- a/PINFuture/Classes/PINFuture+GatherSome.m +++ b/PINFuture/Classes/PINFuture+GatherSome.m @@ -7,6 +7,8 @@ // #import "PINFuture+GatherSome.h" +#import "PINFuture+MapError.h" +#import "PINFuture+GatherAll.h" NS_ASSUME_NONNULL_BEGIN diff --git a/PINFuture/Classes/PINFuture+Generated.h b/PINFuture/Classes/PINFuture+Generated.h index a07db6b..466de7f 100644 --- a/PINFuture/Classes/PINFuture+Generated.h +++ b/PINFuture/Classes/PINFuture+Generated.h @@ -6,9 +6,9 @@ // // -#import - -#import "PINFuture.h" +#import +#import +#import NS_ASSUME_NONNULL_BEGIN diff --git a/PINFuture/Classes/PINFuture+Generated.m b/PINFuture/Classes/PINFuture+Generated.m index 0566fad..cd4bd34 100644 --- a/PINFuture/Classes/PINFuture+Generated.m +++ b/PINFuture/Classes/PINFuture+Generated.m @@ -6,6 +6,11 @@ // #import "PINFuture+Generated.h" +#import "PINFuture+Completion.h" +#import "PINFuture+Dispatch.h" +#import "PINFuture+ChainSideEffect.h" +#import "PINFutureMap+Map.h" +#import "PINFutureMap+FlatMap.h" NS_ASSUME_NONNULL_BEGIN diff --git a/PINFuture/Classes/PINFuture+MapError.h b/PINFuture/Classes/PINFuture+MapError.h index 307876a..170f595 100644 --- a/PINFuture/Classes/PINFuture+MapError.h +++ b/PINFuture/Classes/PINFuture+MapError.h @@ -6,7 +6,8 @@ // Copyright (c) 2016 Pinterest. All rights reserved. // -#import "PINFuture.h" +#import +#import @interface PINFuture (MapError) diff --git a/PINFuture/Classes/PINFuture+MapError.m b/PINFuture/Classes/PINFuture+MapError.m index 2841c1e..42f74ca 100644 --- a/PINFuture/Classes/PINFuture+MapError.m +++ b/PINFuture/Classes/PINFuture+MapError.m @@ -8,6 +8,8 @@ #import "PINFuture+MapError.h" +#import "PINFuture+FlatMapError.h" + @implementation PINFuture (MapError) - (PINFuture *)executor:(id)executor mapError:(id (^)(NSError *error))mapError diff --git a/PINFuture/Classes/PINFuture+MapToValue.h b/PINFuture/Classes/PINFuture+MapToValue.h index 2441ead..7681448 100644 --- a/PINFuture/Classes/PINFuture+MapToValue.h +++ b/PINFuture/Classes/PINFuture+MapToValue.h @@ -6,7 +6,8 @@ // Copyright (c) 2016 Pinterest. All rights reserved. // -#import "PINFuture.h" +#import +#import @interface PINFuture (MapToValue) diff --git a/PINFuture/Classes/PINFuture+MapToValue.m b/PINFuture/Classes/PINFuture+MapToValue.m index 1ed59a7..4432a89 100644 --- a/PINFuture/Classes/PINFuture+MapToValue.m +++ b/PINFuture/Classes/PINFuture+MapToValue.m @@ -8,7 +8,7 @@ #import "PINFuture+MapToValue.h" -#import "PINFutureMap.h" +#import "PINFutureMap+Map.h" @implementation PINFuture (MapToValue) diff --git a/PINFuture/Classes/PINFuture+NoValue.h b/PINFuture/Classes/PINFuture+NoValue.h index c28e7b8..e895ce7 100644 --- a/PINFuture/Classes/PINFuture+NoValue.h +++ b/PINFuture/Classes/PINFuture+NoValue.h @@ -5,9 +5,7 @@ // Created by Chris Danford on 4/16/18. // -#import - -#import "PINFuture.h" +#import /** * A Future that has no meaningful value. Technically, it does have a value (an NSNull). diff --git a/PINFuture/Classes/PINFuture.h b/PINFuture/Classes/PINFuture.h index ecbbfe2..899f8fc 100644 --- a/PINFuture/Classes/PINFuture.h +++ b/PINFuture/Classes/PINFuture.h @@ -8,70 +8,27 @@ #import -#import "PINExecutor.h" -#import "PINDefines.h" - -NS_ASSUME_NONNULL_BEGIN - -/** - * A super-simple future implementation. - * This is a pure objective C implementation that: - * - is thread-safe - * - preserves type safety as much as possible - * - * Non-goals: - * - Don't catch Exceptions in callbacks like Promises/A+. On this platform, Exceptions are generally fatal - * and Errors aren't. - * - * Future improvement ideas: - * - Support progress and cancellation. - */ -@interface PINFuture<__covariant ObjectType> : NSObject - -- (instancetype)init NS_UNAVAILABLE; - -/** - * Return a future that is immediately resolved. - */ -+ (PINFuture *)withValue:(ObjectType)value PIN_WARN_UNUSED_RESULT; - -/** - * Return a future that is immediately rejected. - */ -+ (PINFuture *)withError:(NSError *)error PIN_WARN_UNUSED_RESULT; - -/** - * Construct a future from a block that eventually calls resolve or reject. - * This is slightly dangerous and should only be used when adapting from callbacks to a Future because there's no compiler enforcement - * that all paths of your block will eventually call either `resolve` or `reject`. - */ -+ (PINFuture *)withBlock:(void(^)(void(^resolve)(ObjectType), void(^reject)(NSError *)))block PIN_WARN_UNUSED_RESULT; - -#pragma mark - attach callbacks - -/** - * Execute a block on success or on failure. Use this if you want to have a side-effect and nothing - * needs to wait on your side-effect to complete. - */ -- (void)executor:(id)executor success:(nullable void(^)(ObjectType value))success failure:(nullable void(^)(NSError *error))failure; - -@end - -NS_ASSUME_NONNULL_END - -// Import everything for caller convenience. -#import "PINFuture+ChainSideEffect.h" -#import "PINFuture+Completion.h" -#import "PINFuture+Delay.h" -#import "PINFuture+Dispatch.h" -#import "PINFuture+FlatMapError.h" -#import "PINFuture+GatherAll.h" -#import "PINFuture+GatherSome.h" -#import "PINFuture+MapError.h" -#import "PINFuture+MapToValue.h" -#import "PINFutureMap.h" -#import "PINFutureMap+Map.h" -#import "PINFuture+NoValue.h" -#import "PINFutureMap+FlatMap.h" -#import "PINFuturePending.h" -#import "PINFuture+Generated.h" +#import +#import +#import +#import +#import +#import +#import +#import +#import +#import +#import +#import +#import +#import +#import +#import +#import +#import +#import +#import +#import +#import +#import +#import diff --git a/PINFuture/Classes/PINFutureAndCancelToken.h b/PINFuture/Classes/PINFutureAndCancelToken.h index 8a1dda4..7075306 100644 --- a/PINFuture/Classes/PINFutureAndCancelToken.h +++ b/PINFuture/Classes/PINFutureAndCancelToken.h @@ -5,10 +5,9 @@ // Created by Chris Danford on 1/16/17. // -#import - -#import "PINCancelToken.h" -#import "PINFuture.h" +#import +#import +#import NS_ASSUME_NONNULL_BEGIN diff --git a/PINFuture/Classes/PINFutureDefinition.h b/PINFuture/Classes/PINFutureDefinition.h new file mode 100644 index 0000000..cb89a9b --- /dev/null +++ b/PINFuture/Classes/PINFutureDefinition.h @@ -0,0 +1,61 @@ +// +// PINFutureDefinition.h +// Copyright © 2022-present, Pinterest, Inc. All rights reserved. +// + +#ifndef PINFutureDefinition_h +#define PINFutureDefinition_h + +#import +#import + +NS_ASSUME_NONNULL_BEGIN + +/** + * A super-simple future implementation. + * This is a pure objective C implementation that: + * - is thread-safe + * - preserves type safety as much as possible + * + * Non-goals: + * - Don't catch Exceptions in callbacks like Promises/A+. On this platform, Exceptions are generally fatal + * and Errors aren't. + * + * Future improvement ideas: + * - Support progress and cancellation. + */ +@interface PINFuture<__covariant ObjectType> : NSObject + +- (instancetype)init NS_UNAVAILABLE; + +/** + * Return a future that is immediately resolved. + */ ++ (PINFuture *)withValue:(ObjectType)value PIN_WARN_UNUSED_RESULT; + +/** + * Return a future that is immediately rejected. + */ ++ (PINFuture *)withError:(NSError *)error PIN_WARN_UNUSED_RESULT; + +/** + * Construct a future from a block that eventually calls resolve or reject. + * This is slightly dangerous and should only be used when adapting from callbacks to a Future because there's no compiler enforcement + * that all paths of your block will eventually call either `resolve` or `reject`. + */ ++ (PINFuture *)withBlock:(void(^)(void(^resolve)(ObjectType), void(^reject)(NSError *)))block PIN_WARN_UNUSED_RESULT; + +#pragma mark - attach callbacks + +/** + * Execute a block on success or on failure. Use this if you want to have a side-effect and nothing + * needs to wait on your side-effect to complete. + */ +- (void)executor:(id)executor success:(nullable void(^)(ObjectType value))success failure:(nullable void(^)(NSError *error))failure; + +@end + +NS_ASSUME_NONNULL_END + + +#endif /* PINFutureDefinition_h */ diff --git a/PINFuture/Classes/PINFuture.m b/PINFuture/Classes/PINFutureDefinition.m similarity index 99% rename from PINFuture/Classes/PINFuture.m rename to PINFuture/Classes/PINFutureDefinition.m index 49f82eb..7793781 100644 --- a/PINFuture/Classes/PINFuture.m +++ b/PINFuture/Classes/PINFutureDefinition.m @@ -6,7 +6,7 @@ // Copyright © 2016 Pinterest. All rights reserved. // -#import "PINFuture.h" +#import "PINFutureDefinition.h" #import "PINExecutor.h" #import "PINFutureMap+Map.h" diff --git a/PINFuture/Classes/PINFutureMap+FlatMap.h b/PINFuture/Classes/PINFutureMap+FlatMap.h index fd0dce7..124f76b 100644 --- a/PINFuture/Classes/PINFutureMap+FlatMap.h +++ b/PINFuture/Classes/PINFutureMap+FlatMap.h @@ -8,8 +8,10 @@ #import -#import "PINFuture.h" -#import "PINFutureMap.h" +#import +#import +#import +#import NS_ASSUME_NONNULL_BEGIN diff --git a/PINFuture/Classes/PINFutureMap+Map.h b/PINFuture/Classes/PINFutureMap+Map.h index 85dda3d..bafd3be 100644 --- a/PINFuture/Classes/PINFutureMap+Map.h +++ b/PINFuture/Classes/PINFutureMap+Map.h @@ -8,8 +8,7 @@ #import -#import "PINFuture.h" -#import "PINFutureMap.h" +#import NS_ASSUME_NONNULL_BEGIN diff --git a/PINFuture/Classes/PINFutureOnce.h b/PINFuture/Classes/PINFutureOnce.h index e02b7db..9265231 100644 --- a/PINFuture/Classes/PINFutureOnce.h +++ b/PINFuture/Classes/PINFutureOnce.h @@ -8,7 +8,7 @@ #import -#import "PINDefines.h" +#import @interface PINFutureOnce : NSObject + (instancetype)new PIN_WARN_UNUSED_RESULT; diff --git a/PINFuture/Classes/PINFuturePending.h b/PINFuture/Classes/PINFuturePending.h index 8229831..72da10e 100644 --- a/PINFuture/Classes/PINFuturePending.h +++ b/PINFuture/Classes/PINFuturePending.h @@ -5,7 +5,7 @@ // Created by Ray Cho on 2/20/20. // -#import "PINFuture.h" +#import @interface PINFuturePending : NSObject