Skip to content
This repository has been archived by the owner on Jun 27, 2023. It is now read-only.

Commit

Permalink
Merge pull request #147 from vapor/worker-future
Browse files Browse the repository at this point in the history
Created Worker.succeeded(_:) and .failed(_:) methods
  • Loading branch information
tanner0101 authored May 24, 2018
2 parents a27aa07 + 39c7c5a commit f8ae555
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions Sources/Async/Worker.swift
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,28 @@ extension Worker {
public var eventLoop: EventLoop {
return next()
}

/// Creates a new, succeeded `Future` from the worker's event loop.
///
/// let a: Future<String> = req.future("hello")
///
/// - parameters:
/// - value: The value that the future will wrap.
/// - returns: The succeeded future.
func future<T>(_ value: T) -> Future<T> {
return self.eventLoop.newSucceededFuture(result: value)
}

/// Creates a new, failed `Future` from the worker's event loop.
///
/// let b: Future<String> = req.future(error: Abort(...))
///
/// - parameters:
/// - error: The error that the future will wrap.
/// - returns: The failed future.
func future<T>(error: Error) -> Future<T> {
return self.eventLoop.newFailedFuture(error: error)
}
}

/// A basic `Worker` type that has a single `EventLoop`.
Expand Down

0 comments on commit f8ae555

Please sign in to comment.