diff --git a/3.0/docs/async/promise-future.md b/3.0/docs/async/promise-future.md index 671e4d38..959a1bd5 100644 --- a/3.0/docs/async/promise-future.md +++ b/3.0/docs/async/promise-future.md @@ -121,6 +121,21 @@ futureUsername.then { username in } ``` +## Futures without promise + +In some scenarios you're required to return a `Future` where a `Promise` isn't necessary as you already have the result. + +In these scenarios you can initialize a future with the already completed result. + +```swift +// Already completed on initialization +let future = Future("Hello world!") + +future.then { string in + print(string) +} +``` + ## For synchronous APIs Sometimes, an API needs to be used synchronously in a synchronous envinronment. diff --git a/3.0/docs/http/responder.md b/3.0/docs/http/responder.md index e69de29b..18c237a6 100644 --- a/3.0/docs/http/responder.md +++ b/3.0/docs/http/responder.md @@ -0,0 +1,21 @@ +# Responder + +Responders are a type capable of [responding](response.md) to a [Request](request.md). + +Responders are always [async](../async/promise-future.md) by returning a `Future` by either transforming/mapping an existing future or creating it's own promise. + +## Implementing a static Responder + +```swift +struct StaticResponder: Responder { + let response: Response + + init(response: Response) { + self.response = response + } + + func respond(to req: Request) throws -> Future { + return Future(response) + } +} +```