Skip to content

Commit fc29e84

Browse files
committed
run predictions on background queues
1 parent 5437188 commit fc29e84

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

src/coreml/MLModel+Compat.m

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,20 +7,26 @@ @implementation MLModel (Compat)
77

88
- (void) predictionFromFeatures:(id<MLFeatureProvider>) input
99
completionHandler:(void (^)(id<MLFeatureProvider> output, NSError * error)) completionHandler {
10-
[NSOperationQueue.mainQueue addOperationWithBlock:^{
10+
[NSOperationQueue.new addOperationWithBlock:^{
1111
NSError *error = nil;
1212
id<MLFeatureProvider> prediction = [self predictionFromFeatures:input error:&error];
13-
completionHandler(prediction, error);
13+
14+
[NSOperationQueue.mainQueue addOperationWithBlock:^{
15+
completionHandler(prediction, error);
16+
}];
1417
}];
1518
}
1619

1720
- (void) predictionFromFeatures:(id<MLFeatureProvider>) input
1821
options:(MLPredictionOptions *) options
1922
completionHandler:(void (^)(id<MLFeatureProvider> output, NSError * error)) completionHandler {
20-
[NSOperationQueue.mainQueue addOperationWithBlock:^{
23+
[NSOperationQueue.new addOperationWithBlock:^{
2124
NSError *error = nil;
2225
id<MLFeatureProvider> prediction = [self predictionFromFeatures:input options:options error:&error];
23-
completionHandler(prediction, error);
26+
27+
[NSOperationQueue.mainQueue addOperationWithBlock:^{
28+
completionHandler(prediction, error);
29+
}];
2430
}];
2531
}
2632

0 commit comments

Comments
 (0)