Skip to content

Commit c33dd29

Browse files
Merge pull request #117 from NeedleInAJayStack/doc/async-resolver
Changes documentation examples to async/await
2 parents dfbefc2 + 83abed6 commit c33dd29

File tree

1 file changed

+16
-5
lines changed

1 file changed

+16
-5
lines changed

README.md

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -200,13 +200,12 @@ defer {
200200
try? group.syncShutdownGracefully()
201201
}
202202

203-
api.execute(
203+
let result = try await api.execute(
204204
request: "{ message { content } }",
205205
context: Context(),
206206
on: group
207-
).whenSuccess { result in
208-
print(result)
209-
}
207+
)
208+
print(result)
210209
```
211210

212211
The output will be:
@@ -219,7 +218,19 @@ The output will be:
219218

220219
#### Async resolvers
221220

222-
To use async resolvers, just add one more parameter with type `EventLoopGroup` to the resolver function and change the return type to `EventLoopFuture<YouReturnType>`. Don't forget to import NIO.
221+
Resolver functions can also be `async`:
222+
223+
```swift
224+
struct Resolver {
225+
func message(context: Context, arguments: NoArguments) async -> Message {
226+
await someAsyncMethodToGetMessage()
227+
}
228+
}
229+
```
230+
231+
#### NIO resolvers
232+
233+
The resolver functions also support `NIO`-style concurrency. To do so, just add one more parameter with type `EventLoopGroup` to the resolver function and change the return type to `EventLoopFuture<YouReturnType>`. Don't forget to import NIO.
223234

224235
```swift
225236
import NIO

0 commit comments

Comments
 (0)