title: Swift Combine correct use of Future
body: <p>Say I have a three layered architecture (Data, Domain and View) and I want to access and provide some data. The three layers are part of different targets and are initialised using dependency injection.</p>
  <p>In the domain layer I have the following types:</p>
  <pre class="lang-swift prettyprint-override"><code>protocol BookListRepository: AnyObject {
      func getAll() -&gt; Future&lt;[Book], Error&gt;
  }
  </code></pre>
  <pre class="lang-swift prettyprint-override"><code>final class BookService {
      private let repository: BookListRepository
  
      init(repository: BookListRepository) {
          self.repository = repository
      }
  
      func getAll() -&gt; Future&lt;[Book], Error&gt; {
          repository.getAll()
      }
  }
  </code></pre>
  <p>In data I define the following:</p>
  <pre class="lang-swift prettyprint-override"><code>class BookApi: BookListRepository {
      func getAll() -&gt; Future&lt;[Book], Error&gt; {
          .init { promise in
              let cancellable = urlSession
                  .dataTaskPublisher(for: url)
                  .tryMap() { element -&gt; Data in
                      guard 
                          let httpResponse = element.response as? HTTPURLResponse,
                          httpResponse.statusCode == 200 
                      else { throw URLError(.badServerResponse) }
                      return element.data
                  }
                  .decode(type: [Book]].self, decoder: JSONDecoder())
                  .sink(receiveCompletion: { completion in
                      guard case let .failure(error) = completion
                      promise(.failure(error))
                   },
                  receiveValue: { books in 
                      promise(.success(books))
                  }
      }
  }
  </code></pre>
  <p>In my view layer I would access this in a similar way to this:</p>
  <pre class="lang-swift prettyprint-override"><code>let service: BookService = .init(repository: BookApi())
  service
      .getAll()
      .receive(on: DispatchQueue.main)
      .sink(receiveCompletion: { print($0) }) { books in
          // Displau
      }
      .store(in: &amp;cancelables)
  </code></pre>
  <p>My question here is the following: Is this in any way a good practice and if not what is the correct/preferred way to achieve what I want.</p>