Skip to content

Instantly share code, notes, and snippets.

@prachigauriar
Last active August 29, 2015 14:12
Show Gist options
  • Save prachigauriar/0ababa76f74edfd43f54 to your computer and use it in GitHub Desktop.
Save prachigauriar/0ababa76f74edfd43f54 to your computer and use it in GitHub Desktop.
Synchronous Subworkflow Task
//
// SynchronousSubworkflowTask.h
// SynchronousSubworkflowTask
//
// Created by Prachi Gauriar on 1/5/2015.
// Copyright (c) 2015 Prachi Gauriar. All rights reserved.
//
#import <Task/Task.h>
@interface SynchronousSubworkflowTask : TSKSubworkflowTask
@end
//
// SynchronousSubworkflowTask.m
// SynchronousSubworkflowTask
//
// Created by Prachi Gauriar on 1/5/2015.
// Copyright (c) 2015 Prachi Gauriar. All rights reserved.
//
#import "SynchronousSubworkflowTask.h"
@interface SynchronousSubworkflowTask ()
@property (nonatomic, strong) dispatch_group_t dispatchGroup;
@end
@implementation SynchronousSubworkflowTask
- (instancetype)initWithName:(NSString *)name subworkflow:(TSKWorkflow *)subworkflow
{
self = [super initWithName:name subworkflow:subworkflow];
if (self) {
_dispatchGroup = dispatch_group_create();
}
return self;
}
- (void)main
{
dispatch_group_enter(self.dispatchGroup);
[super main];
dispatch_group_wait(self.dispatchGroup, DISPATCH_TIME_FOREVER);
}
- (void)didFinishWithResult:(id)result
{
dispatch_group_leave(self.dispatchGroup);
}
- (void)didFailWithError:(NSError *)error
{
dispatch_group_leave(self.dispatchGroup);
}
- (void)didCancel
{
dispatch_group_leave(self.dispatchGroup);
}
- (void)didReset
{
dispatch_group_leave(self.dispatchGroup);
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment