CombineExt icon indicating copy to clipboard operation
CombineExt copied to clipboard

operators: add fromAsync, fromThrowingAsync, fromAsyncSequence

Open twittemb opened this issue 3 years ago • 5 comments

This PR bridges structured concurrency with Combine by adding:

  • Publishers.fromAsync(): wraps an async function call into an AnyPublisher<Output, Never>
  • Publishers.fromThrowingAsync(): wraps a throwing async function call into an AnyPublisher<Output, Error>
  • Publishers.fromAsyncSequence(): wraps an async sequence into an AnyPublisher<Output, Error>

The CI has been adapted to allow the usage of Xcode 13/Swift 5.5.

The SPM section has been removed since xcodebuild can now run swift packages (no Xcode project generate needed).

twittemb avatar Sep 26 '21 12:09 twittemb

Codecov Report

Merging #106 (359d0fd) into main (fc3e405) will decrease coverage by 2.02%. The diff coverage is n/a.

:exclamation: Current head 359d0fd differs from pull request most recent head 52c52be. Consider uploading reports for the commit 52c52be to get more accurate results Impacted file tree graph

@@            Coverage Diff             @@
##             main     #106      +/-   ##
==========================================
- Coverage   97.23%   95.21%   -2.03%     
==========================================
  Files          62       60       -2     
  Lines        3323     3236      -87     
==========================================
- Hits         3231     3081     -150     
- Misses         92      155      +63     
Impacted Files Coverage Δ
Sources/Operators/SetOutputType.swift 50.00% <0.00%> (-50.00%) :arrow_down:
Sources/Operators/IgnoreOutputSetOutputType.swift 50.00% <0.00%> (-50.00%) :arrow_down:
Tests/OptionalTests.swift 94.44% <0.00%> (-5.56%) :arrow_down:
Sources/Models/Event.swift 47.36% <0.00%> (-5.27%) :arrow_down:
Sources/Common/Sink.swift 50.00% <0.00%> (-5.00%) :arrow_down:
Tests/FlatMapBatchesTests.swift 95.34% <0.00%> (-4.66%) :arrow_down:
Tests/PrefixDurationTests.swift 95.34% <0.00%> (-4.66%) :arrow_down:
Sources/Common/DemandBuffer.swift 96.15% <0.00%> (-3.85%) :arrow_down:
Tests/DematerializeTests.swift 93.75% <0.00%> (-3.75%) :arrow_down:
Tests/PartitionTests.swift 96.29% <0.00%> (-3.71%) :arrow_down:
... and 19 more

Continue to review full report at Codecov.

Legend - Click here to learn more Δ = absolute <relative> (impact), ø = not affected, ? = missing data Powered by Codecov. Last update fc3e405...52c52be. Read the comment docs.

codecov[bot] avatar Sep 26 '21 12:09 codecov[bot]

@freak4pc the code coverage does not seem happy, but I don't know why. The new code has a 100% coverage but the overall percentage seems to be lower than before.Do you know why ? (it's like that unit tests code coverage is taken into account)

twittemb avatar Sep 26 '21 12:09 twittemb

Hi @freak4pc, do you have an idea of what's going on with the code coverage ?

Do we want to go forward with this async/await -> Combine bridge ?

twittemb avatar Oct 09 '21 11:10 twittemb

is there an update on this?

markst avatar Aug 01 '22 15:08 markst

Seems .subscribe(on: RunLoop.main) has no effect:

Publishers.fromThrowingAsync(priority: TaskPriority.background, { () -> [EventEntity] in
    let result = try await self.useCase.invoke(forceRefresh: true)
    return result
})
.subscribe(on: RunLoop.main)
.eraseToAnyPublisher()

The asyncThrowingFunction is called on whatever thread the publisher was created from.

markst avatar Aug 01 '22 16:08 markst