title: How to use EventLoopFuture in Swift properly?
body: <p>I'm new to EventLoop futures and promises. My software stack:</p>
  
  <ul>
  <li>Backend in Go + gRPC</li>
  <li>iOS client in Swift + SwiftUI + GRPC + NIO</li>
  </ul>
  
  <p>I've got something to work and looking for suggestions on how to improve it since I'm a little lost in docs around <code>.map</code>, <code>.flatMap</code>, <code>.always</code>, etc.</p>
  
  <p>Here's a relevant function from my gRPC data singleton within iOS app:</p>
  
  <pre><code>import Foundation
  import NIO
  import GRPC
  
  class DataRepository {
      static let shared = DataRepository()
      // skip ...
  
      func readItem(id: Int64, eventLoop: EventLoop) -&gt; EventLoopFuture&lt;V1_ReadResponse&gt; {
          // TODO: Is this the right place?
          defer {
              try? eventLoop.syncShutdownGracefully()
          }
  
          let promise = eventLoop.makePromise(of: V1_ReadResponse.self)
  
          var request = V1_ReadRequest()
          request.api = "v1"
          request.id = id
  
          let call = client.read(request, callOptions: callOptions) // client - GRPCClient initialized in the singleton
  
          call.response.whenSuccess{ response in
              return promise.succeed(response)
          }
  
          call.response.whenFailure{ error in
              return(promise.fail(error))
          }
  
          return promise.futureResult
      }
  </code></pre>
  
  <p>My code in SwiftUI View:</p>
  
  <pre><code>import SwiftUI
  import NIO
  
  struct MyView : View {
      @State private var itemTitle = "None"
  
      var body: some View {
          Text(itemTitle)
      }
  
      func getItem() {
          let eventLoopGroup = MultiThreadedEventLoopGroup(numberOfThreads: 1)
          let result = DataRepository.shared.readItem(id: 1, eventLoop: eventLoopGroup.next())
  
          _ = result.always { (response: Result&lt;V1_ReadResponse, Error&gt;) in
  
              let res = try? response.get()                
              if let resExist = res {
                  self.itemTitle = resExist.item.title
              }
  
              _ = response.mapError{ (err: Error) -&gt; Error in
                  print("[Error] Connection error or item not found: \(err)")
                  return err
              }
          }
      }
  </code></pre>
  
  <p>Should I refactor <code>getItem</code> and/or <code>readItem</code>? Any specific suggestions?</p>