This repository has been archived on 2024-07-22. You can view files and clone it, but cannot push or open issues or pull requests.
Doric/iOS/Pod/Classes/DoricAsyncResult.m

63 lines
1.4 KiB
Mathematica
Raw Normal View History

2019-07-26 14:19:42 +08:00
//
// DoricAsyncResult.m
// Doric
//
// Created by pengfei.zhou on 2019/7/26.
//
#import "DoricAsyncResult.h"
@interface DoricAsyncResult()
@property(nonatomic,strong) id result;
@property(nonatomic,strong) DoricResultCallback resultCallback;
@property(nonatomic,strong) DoricExceptionCallback exceptionCallback;
@property(nonatomic,strong) DoricFinishCallback finishCallback;
@end
@implementation DoricAsyncResult
-(void)setupResult:(id)result {
self.result = result;
if(self.resultCallback){
self.resultCallback(result);
}
if(self.finishCallback){
self.finishCallback();
}
}
-(void)setupError:(NSException *)exception {
self.result = exception;
if(self.exceptionCallback){
self.exceptionCallback(exception);
}
if(self.finishCallback){
self.finishCallback();
}
}
-(BOOL)hasResult {
return self.result;
}
-(id)getResult {
return self.result;
}
-(void)setResultCallback:(DoricResultCallback)callback exceptionCallback:(DoricExceptionCallback)exceptionCallback {
self.resultCallback = callback;
self.exceptionCallback = exceptionCallback;
if([self.result isKindOfClass: [NSException class]]){
self.exceptionCallback(self.result);
}else if(self.result){
self.resultCallback(self.result);
}
}
-(void)setFinishCallback:(DoricFinishCallback)callback {
self.finishCallback = callback;
if(self.result){
callback();
}
}
@end