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

operators: add fromAsync, fromThrowingAsync, fromAsyncSequence #106

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

twittemb
Copy link
Member

@twittemb twittemb commented Sep 26, 2021

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).

@codecov
Copy link

codecov bot commented Sep 26, 2021

Codecov Report

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

❗ 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%) ⬇️
Sources/Operators/IgnoreOutputSetOutputType.swift 50.00% <0.00%> (-50.00%) ⬇️
Tests/OptionalTests.swift 94.44% <0.00%> (-5.56%) ⬇️
Sources/Models/Event.swift 47.36% <0.00%> (-5.27%) ⬇️
Sources/Common/Sink.swift 50.00% <0.00%> (-5.00%) ⬇️
Tests/FlatMapBatchesTests.swift 95.34% <0.00%> (-4.66%) ⬇️
Tests/PrefixDurationTests.swift 95.34% <0.00%> (-4.66%) ⬇️
Sources/Common/DemandBuffer.swift 96.15% <0.00%> (-3.85%) ⬇️
Tests/DematerializeTests.swift 93.75% <0.00%> (-3.75%) ⬇️
Tests/PartitionTests.swift 96.29% <0.00%> (-3.71%) ⬇️
... 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.

@twittemb
Copy link
Member Author

@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 twittemb requested a review from freak4pc September 26, 2021 12:41
@twittemb
Copy link
Member Author

twittemb commented Oct 9, 2021

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 ?

@markst
Copy link

markst commented Aug 1, 2022

is there an update on this?

#if canImport(Combine)
import Combine

@available(macOS 12.0, iOS 15.0, tvOS 15.0, watchOS 8.0, *)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe this can be:

#if compiler(>=5.5) && canImport(_Concurrency)

rather than forcing iOS15

https://www.swiftbysundell.com/special/swift-concurrency-backward-compatibility/

@markst
Copy link

markst commented Aug 1, 2022

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.

@@ -0,0 +1,91 @@
<?xml version="1.0" encoding="UTF-8"?>

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you should not commit this file.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add this to gitignore:

# Ignore all schemes located in swiftpm
**/.swiftpm/**/xcschemes/

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.

3 participants