Skip to content

Commit f2847cf

Browse files
committed
used new sleep
1 parent 936c846 commit f2847cf

File tree

3 files changed

+6
-16
lines changed

3 files changed

+6
-16
lines changed

ExecutionContext/CustomExecutionContext.swift

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,8 @@ public class CustomExecutionContext : ExecutionContextBase, ExecutionContextType
2828
}
2929

3030
public func async(after:Double, task:SafeTask) {
31-
let sec = time_t(after)
32-
let nsec = Int((after - Double(sec)) * 1000 * 1000 * 1000)//nano seconds
33-
var time = timespec(tv_sec:sec, tv_nsec: nsec)
34-
3531
async {
36-
nanosleep(&time, nil)
32+
sleep(after)
3733
task()
3834
}
3935
}

ExecutionContext/ImmediateExecutionContext.swift

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,10 @@ public class ImmediateExecutionContext : ExecutionContextBase, ExecutionContextT
2222
}
2323

2424
public func async(after:Double, task:SafeTask) {
25-
let sec = time_t(after)
26-
let nsec = Int((after - Double(sec)) * 1000 * 1000 * 1000)//nano seconds
27-
var time = timespec(tv_sec:sec, tv_nsec: nsec)
28-
29-
nanosleep(&time, nil)
30-
async(task)
25+
async {
26+
sleep(after)
27+
task()
28+
}
3129
}
3230

3331
public func sync<ReturnType>(task:() throws -> ReturnType) throws -> ReturnType {

ExecutionContext/PThreadExecutionContext.swift

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -196,11 +196,7 @@
196196

197197
func async(after:Double, task:SafeTask) {
198198
let thread = PThread(task: {
199-
let sec = time_t(after)
200-
let nsec = Int((after - Double(sec)) * 1000 * 1000 * 1000)//nano seconds
201-
var time = timespec(tv_sec:sec, tv_nsec: nsec)
202-
203-
nanosleep(&time, nil)
199+
sleep(after)
204200
task()
205201
})
206202
thread.start()

0 commit comments

Comments
 (0)