Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SPT-1998 Поддержка отмены таски для Combine (2) #137

Merged
merged 4 commits into from
May 24, 2024

Conversation

mrandrewsmith
Copy link
Collaborator

Восстановленный пр, закрытый после удаления base ветки.

Что сделано

  • Созданы кастомные Publisher для AsyncNode и AsyncStreamNode с поддержкой отмены Task. Интерфейс и реализация сделаны по аналогии с URLSession DataTaskPublisher.

Примеры использования

Теперь для AsyncNode и AsyncStreamNode интерфейс один, но для каждого из них будет создан свой Publisher:

ChainConfigurator()
    .build() // <- Возвращает AsyncNode
    .nodeResultPublisher()
    .sink {
    }

ChainConfigurator()
    .build() // <- Возвращает AsyncStreamNode
    .nodeResultPublisher()
    .sink {
    }

При отмене подписки будет вызван cancel у созданной таски:

let cancellable = ChainConfigurator()
    .build()
    .nodeResultPublisher()
    .sink {
    }

cancellable.cancel()

При каждой новой подписке будет создана новая таска с вызовом метода process()

let publisher = ChainConfigurator()
    .build()
    .nodeResultPublisher()

publisher.sink { // <- Создается новая таска и вызывается метод  process
}

publisher.sink { // <- Создается новая таска и вызывается метод  process
}

Шарить результат можно стандартными средствами Combine:

let multicast = ChainConfigurator()
    .build()
    .nodeResultPublisher()
    .multicast { PassthroughSubject() }

multicast.sink { // <- Новая таска не создается
}

multicast.sink { // <- Новая таска не создается
}

multicast.connect() // <- Создается новая таска и вызывается метод  process

@mrandrewsmith mrandrewsmith self-assigned this May 13, 2024
@mrandrewsmith mrandrewsmith changed the title SPT-1998 Поддержка отмены таски для Combine SPT-1998 Поддержка отмены таски для Combine (2) May 13, 2024
@codecov-commenter
Copy link

codecov-commenter commented May 13, 2024

Codecov Report

Attention: Patch coverage is 87.50000% with 10 lines in your changes are missing coverage. Please review.

Project coverage is 91.08%. Comparing base (c114116) to head (58cdde8).
Report is 3 commits behind head on 5.0.0.

Files Patch % Lines
...e/Node/Combine/Subscription/BaseSubscription.swift 70.58% 10 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##            5.0.0     #137      +/-   ##
==========================================
- Coverage   91.52%   91.08%   -0.44%     
==========================================
  Files          85       87       +2     
  Lines        1262     1313      +51     
==========================================
+ Hits         1155     1196      +41     
- Misses        107      117      +10     
Flag Coverage Δ
tests 91.08% <87.50%> (-0.44%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@mrandrewsmith mrandrewsmith changed the base branch from SPT-1998-refactor-builders-and-add-mocks to 5.0.0 May 24, 2024 10:47
@mrandrewsmith mrandrewsmith merged commit 606d1ea into 5.0.0 May 24, 2024
3 checks passed
@mrandrewsmith mrandrewsmith deleted the SPT-1998-combine-task-cancelation branch June 13, 2024 08:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants