Swift Concurrency Essentials: Task Cancellation

Поделиться
HTML-код
  • Опубликовано: 5 ноя 2024

Комментарии • 4

  • @zackzack7477
    @zackzack7477 2 года назад +1

    exactly the video i needed to watch, thank you!

  • @trippleqasim
    @trippleqasim Год назад

    Hi, why we did not check the isCancelled on "searchHandle" because we already have the reference of the current running task could you please help me for this confusion

  • @30guarino
    @30guarino 3 года назад

    Hey Great video.... I have a question about using 'Task' ...so when using async / await use 'Task' to cancel and make search results appear in the correct order.... then is it correct when NOT using async / await we use Set and then call .store() after the receive and sink calls ?

    • @PeterFriese
      @PeterFriese  3 года назад +3

      So when using Combine, you would use switchToLatest() to cancel any previous requests:
      $searchTerm
      .debounce(for: 0.8, scheduler: RunLoop.main)
      .removeDuplicates()
      .map { searchTerm -> AnyPublisher in
      self.searchBooks(searchTerm: searchTerm)
      }
      .switchToLatest()
      .receive(on: RunLoop.main)
      .assign(to: &$result)
      (see gist.github.com/peterfriese/77682a28490c0c11ce2ec49575fca057)