Add deadlines as an alternative to timeouts (#770)

Add deadlines as an alternative to timeouts

Motivation:

Address #603

Modifications:

- Add NIODeadline type
- Add func scheduleTask<T>(deadline: NIODeadline, _ task: @escaping () throws -> T) -> Scheduled<T>
- Reduce the use of DispatchTime in favor of Time
- Replace timeout calls with deadline calls where it makes sense

Result:

Tasks can be scheduled after an amount of time has passed, or at a certain time.
This commit is contained in:
David Skrundz authored and Johannes Weiss committed 2019-01-25 19:32:55 +00:00
1 parent de8d3e260e
commit 0eb85a4478
13 files changed
+172 -76

No files matched your search

+1 -2
View File
@@ -12,7 +12,6 @@
//
//===----------------------------------------------------------------------===//
import Dispatch
import NIO
import NIOHTTP1
import NIOWebSocket
@@ -145,7 +144,7 @@ private final class WebSocketTimeHandler: ChannelInboundHandler {
// We can't really check for error here, but it's also not the purpose of the
// example so let's not worry about it.
let theTime = DispatchTime.now().uptimeNanoseconds
let theTime = NIODeadline.now().uptimeNanoseconds
var buffer = ctx.channel.allocator.buffer(capacity: 12)
buffer.write(string: "\(theTime)")