mirror of
https://github.com/oxen-io/session-ios.git
synced 2023-12-13 21:30:14 +01:00
f1de95ab06
FREEBIE
59 lines
1.4 KiB
Objective-C
59 lines
1.4 KiB
Objective-C
#import "Util.h"
|
|
#import "Constraints.h"
|
|
|
|
@implementation Operation
|
|
|
|
+(Operation*) operation:(Action)block {
|
|
require(block != NULL);
|
|
Operation* a = [Operation new];
|
|
a->_callback = block;
|
|
return a;
|
|
}
|
|
|
|
+(void) asyncRun:(Action)action
|
|
onThread:(NSThread*)thread {
|
|
|
|
require(action != nil);
|
|
require(thread != nil);
|
|
|
|
[[Operation operation:action] performOnThread:thread];
|
|
}
|
|
|
|
+(void) asyncRunAndWaitUntilDone:(Action)action
|
|
onThread:(NSThread*)thread {
|
|
|
|
require(action != nil);
|
|
require(thread != nil);
|
|
|
|
[[Operation operation:action] performOnThreadAndWaitUntilDone:thread];
|
|
}
|
|
|
|
+(void) asyncRunOnNewThread:(Action)action {
|
|
require(action != nil);
|
|
[[Operation operation:action] performOnNewThread];
|
|
}
|
|
|
|
-(SEL) selectorToRun {
|
|
return @selector(run);
|
|
}
|
|
|
|
-(void) performOnThread:(NSThread*)thread {
|
|
require(thread != nil);
|
|
[self performSelector:@selector(run) onThread:thread withObject:nil waitUntilDone:thread == NSThread.currentThread];
|
|
}
|
|
|
|
-(void) performOnThreadAndWaitUntilDone:(NSThread*)thread {
|
|
require(thread != nil);
|
|
[self performSelector:@selector(run) onThread:thread withObject:nil waitUntilDone:true];
|
|
}
|
|
|
|
-(void) performOnNewThread {
|
|
[NSThread detachNewThreadSelector:[self selectorToRun] toTarget:self withObject:nil];
|
|
}
|
|
|
|
-(void) run {
|
|
_callback();
|
|
}
|
|
|
|
@end
|