Skip to content

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

Unable to cancel an concatenated Effect before it's being run. #3563

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

Closed
1 of 3 tasks
RoBo-Inc opened this issue Jan 24, 2025 · 1 comment
Closed
1 of 3 tasks

Unable to cancel an concatenated Effect before it's being run. #3563

RoBo-Inc opened this issue Jan 24, 2025 · 1 comment

Comments

@RoBo-Inc
Copy link

RoBo-Inc commented Jan 24, 2025

Description

return .concatenate(longLivingEffects)
I want to have a possibility to cancel one of those pending (in the queue) effects.
Unfortunately, the standard return .cancel(id: particularEffectId) doesn't seem to work. (Which it probably should — it feels like it would be an 'expected behavior')

It's probably related to this issue

Checklist

  • I have determined whether this bug is also reproducible in a vanilla SwiftUI project.
  • If possible, I've reproduced the issue using the main branch of this package.
  • This issue hasn't been addressed in an existing GitHub issue or discussion.

Expected behavior

Canceled effects should be canceled regardless of whether they have already started executing or not.

Actual behavior

Effects only get canceled if they have already started executing.

Reproducing project

I have open-sourced simple project which is suitable for the issue illustration. It's not exactly "distilled", but it's basically clone of ReusableComponents-Downloadcase-study.
https://github.com/RoBo-Inc/ReusableComponents-Download
The issue is illustrated by the very last commit (tagged 4.0.0). On that commit I added a feature: automatically start loading files one-by-one on the app launch. It works exactly as I want, and it's amazing that I achieved the desired behavior basically with the single line of code: return .concatenate(state.cityMapRows.ids.map { rowComponent(state, id: $0, action: .start) }) (in CityMaps.swift file)
But... there is a bug (or rather unexpected behavior). Let's say we start the app, the files begin downloading, and we decided that we don't want to download some particular file. So we click on it and cancel the downloading (via the popup dialog). At first all looks good, but when the downloading queue reaches the file, it starts to download anyways.

Of course there is a workaround for this example. But it requires much more then one line of code, and even additional tracking downloading state variable. So it would be much nicer if it just works out of the box from the beginning 🙂

The Composable Architecture version information

1.17.0

Destination operating system

iOS 18

Xcode version information

16.2

Swift Compiler version information

swift-driver version: 1.115.1 Apple Swift version 6.0.3 (swiftlang-6.0.3.1.10 clang-1600.0.30.1)
Target: arm64-apple-macosx15.0
@RoBo-Inc RoBo-Inc added the bug Something isn't working due to a bug in the library. label Jan 24, 2025
@mbrandonw
Copy link
Member

Hi @RoBo-Inc, this project is a little too complex for us to dive into and understand the issue you are seeing. Can you please minimize it, and ideally write a test that should pass in your opinion but does not?

Since it isn't clear this is an issue with the library, or perhaps even a duplicate of #1848, I am going to convert this to a discussion. Please feel free to continue the conversation over there!

@mbrandonw mbrandonw removed the bug Something isn't working due to a bug in the library. label Jan 24, 2025
@pointfreeco pointfreeco locked and limited conversation to collaborators Jan 24, 2025
@mbrandonw mbrandonw converted this issue into discussion #3566 Jan 24, 2025

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants