Skip to content

Commit

Permalink
Merge pull request #5 from 0xLeif/develop
Browse files Browse the repository at this point in the history
Allow `main` to return `LaterValue<T>`
  • Loading branch information
0xLeif authored Aug 24, 2020
2 parents 83d7196 + d6c9f78 commit 12a3b6d
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion Sources/Later/Later.swift
Original file line number Diff line number Diff line change
Expand Up @@ -104,9 +104,24 @@ public extension Later {

}
}

@discardableResult
static func main<T>(withDelay delay: UInt32 = 0,
work: @escaping () throws -> T) -> LaterValue<T> {
promise { promise in
sleep(delay)
DispatchQueue.main.async {
do {
let view = try work()
promise.succeed(view)
} catch {
promise.fail(error)
}
}
}
}
}


// MARK: schedule

public extension Later {
Expand Down

0 comments on commit 12a3b6d

Please sign in to comment.