Skip to content

Commit

Permalink
Simplify IceStorm/clock signal handling in Swift
Browse files Browse the repository at this point in the history
  • Loading branch information
pepone committed Sep 5, 2019
1 parent b9e466f commit 4470100
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions swift/IceStorm/clock/Sources/Publisher/main.swift
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,12 @@ func run() -> Int32 {
let sigintSource = DispatchSource.makeSignalSource(signal: SIGINT, queue: DispatchQueue.main)
sigintSource.setEventHandler {
communicator.destroy()
exit(0)
}
sigintSource.resume()

let sigtermSource = DispatchSource.makeSignalSource(signal: SIGTERM, queue: DispatchQueue.main)
sigtermSource.setEventHandler {
communicator.destroy()
exit(0)
}
sigtermSource.resume()

Expand Down Expand Up @@ -120,9 +118,12 @@ func run() -> Int32 {
let t = DispatchSource.makeTimerSource()
t.schedule(deadline: .now(), repeating: .seconds(1))
t.setEventHandler {
firstly {
clock.tickAsync(dateFormatter.string(from: Date()))
}.catch { _ in
do {
try clock.tick(dateFormatter.string(from: Date()))
} catch is CommunicatorDestroyedException {
t.suspend()
exit(0)
} catch {
t.suspend()
communicator.destroy()
exit(1)
Expand Down

0 comments on commit 4470100

Please sign in to comment.