Skip to content

Commit 38a355d

Browse files
author
Edward Smith
committed
Merge from Apple-Shared-Source.
1 parent 2123fda commit 38a355d

File tree

3 files changed

+55
-1
lines changed

3 files changed

+55
-1
lines changed

Branch-SDK-Tests/Branch-SDK-Tests/BNCTestCase.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
#import <XCTest/XCTest.h>
1010
#import <OCMock/OCMock.h>
1111
#import "NSString+Branch.h"
12-
#import "BNCUtilities.h"
12+
#import "BNCThreads.h"
1313

1414
#define BNCTAssertEqualMaskedString(string, mask) { \
1515
if ((id)string != nil && (id)mask != nil && [string bnc_isEqualToMaskedString:mask]) { \

Branch-SDK/Branch-SDK/BNCThreads.h

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/**
2+
@file BNCThreads.h
3+
@package Branch-SDK
4+
@brief Utilities for working with threads, queues, and blocks.
5+
6+
@author Edward Smith
7+
@date May 2017
8+
@copyright Copyright © 2017 Branch. All rights reserved.
9+
*/
10+
11+
#if __has_feature(modules)
12+
@import Foundation;
13+
#else
14+
#import <Foundation/Foundation.h>
15+
#endif
16+
17+
///@group Blocks and Threads
18+
#pragma mark - Blocks and Threads
19+
20+
static inline dispatch_time_t BNCDispatchTimeFromSeconds(NSTimeInterval seconds) {
21+
return dispatch_time(DISPATCH_TIME_NOW, seconds * NSEC_PER_SEC);
22+
}
23+
24+
static inline void BNCAfterSecondsPerformBlockOnMainThread(NSTimeInterval seconds, dispatch_block_t block) {
25+
dispatch_after(BNCDispatchTimeFromSeconds(seconds), dispatch_get_main_queue(), block);
26+
}
27+
28+
static inline void BNCPerformBlockOnMainThreadAsync(dispatch_block_t block) {
29+
dispatch_async(dispatch_get_main_queue(), block);
30+
}
31+
32+
static inline uint64_t BNCNanoSecondsFromTimeInterval(NSTimeInterval interval) {
33+
return interval * ((NSTimeInterval) NSEC_PER_SEC);
34+
}
35+
36+
static inline void BNCSleepForTimeInterval(NSTimeInterval seconds) {
37+
double secPart = trunc(seconds);
38+
double nanoPart = trunc((seconds - secPart) * ((double)NSEC_PER_SEC));
39+
struct timespec sleepTime;
40+
sleepTime.tv_sec = (__typeof(sleepTime.tv_sec)) secPart;
41+
sleepTime.tv_nsec = (__typeof(sleepTime.tv_nsec)) nanoPart;
42+
nanosleep(&sleepTime, NULL);
43+
}

Branch-SDK/Branch-SDK/BNCThreads.m

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
/**
2+
@file BNCThreads.m
3+
@package Branch-SDK
4+
@brief Utilities for working with threads, queues, and blocks.
5+
6+
@author Edward Smith
7+
@date May 2017
8+
@copyright Copyright © 2017 Branch. All rights reserved.
9+
*/
10+
11+
#import "BNCThreads.h"

0 commit comments

Comments
 (0)