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

Proposal: Add ability to specify execution queue in EffectRouter #155

Merged
merged 7 commits into from
Apr 21, 2020

Conversation

jeppes
Copy link
Contributor

@jeppes jeppes commented Apr 21, 2020

This adds the ability to specify which queue an effect should be handled on in the EffectRouter with the following syntax:

EffectRouter<Effect, Event>()
    .routeCase(...)
    .on(.main) // <--- execute this effect on the main thread
    .to { /* some UI action */ }

Previously, this would have required writing:

EffectRouter<Effect, Event>()
    .routeCase(...)
    .to { 
        DispatchQueue.main.async { 
            // Some UI action
        }
    }

This can safely be used in both raw loops and in MobiusController loops.

@JensAyton @pettermahlen

/// Handle an the current `Effect` asynchronously on the provided `DispatchQueue`
///
/// - Parameter queue: The `DispatchQueue` that the current `Effect` should be handled on.
public func on(_ queue: DispatchQueue) -> Self {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is currently returning Self, which means that .on(..) can be called multiple times on the same route.

This could be solved by adding another intermediate type. I'm not sure this is worth it.

We could also crash if a queue has already been set. Again, I think the risk of this is quite low, but we can discuss this further here in the comments.

Copy link
Contributor

Choose a reason for hiding this comment

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

I think this is fine

@codecov
Copy link

codecov bot commented Apr 21, 2020

Codecov Report

Merging #155 into master will increase coverage by 0.02%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #155      +/-   ##
==========================================
+ Coverage   94.47%   94.50%   +0.02%     
==========================================
  Files          46       46              
  Lines        1284     1291       +7     
==========================================
+ Hits         1213     1220       +7     
  Misses         71       71              
Flag Coverage Δ
#ios 94.50% <100.00%> (+0.02%) ⬆️
#macspm 94.44% <100.00%> (+0.03%) ⬆️
Impacted Files Coverage Δ
...obiusCore/Source/EffectHandlers/EffectRouter.swift 98.24% <100.00%> (+0.24%) ⬆️

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 44275ab...12f0194. Read the comment docs.

@jeppes jeppes merged commit 14df798 into spotify:master Apr 21, 2020
@jeppes jeppes deleted the handle-effect-on-queue branch April 21, 2020 16:25
@kmcbride kmcbride mentioned this pull request Oct 30, 2020
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.

2 participants