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

CancellationTokenSource not disposed #1234

Closed
kzhui125 opened this issue Aug 2, 2023 · 1 comment
Closed

CancellationTokenSource not disposed #1234

kzhui125 opened this issue Aug 2, 2023 · 1 comment

Comments

@kzhui125
Copy link

kzhui125 commented Aug 2, 2023

Hi,

for the following code, in struct Aff<RT, A>.Timeout, it will call env.LocalCancel to create a new CancellationTokenSource.

if task is complete before the timeout, I don't see place to dispose the lenv.CancellationTokenSource.

Maybe this is not a best practice, since Microsoft docs suggests that we should dispose a CancellationTokenSource when complete.

public static Aff<RT, Unit> Main => repeat(
    from _1 in Delay(TimeSpan.FromMilliseconds(10)).Timeout(TimeSpan.FromHours(1))
    from _2 in Console<RT>.WriteLine($"{DateTime.Now:hh:mm:ss}")
    select unit);

private static Aff<RT, Unit> Delay(TimeSpan delay) => Aff<RT, Unit>(async _ =>
{
    await Task.Delay(delay);
    return unit;
});

Thanks,

@louthy
Copy link
Owner

louthy commented Aug 7, 2023

Good spot! Fix is done and will be deployed this week 👍

@louthy louthy closed this as completed Nov 17, 2023
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

No branches or pull requests

2 participants