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

fix: use empty cancellation reason as default #32

Merged

Conversation

dankeboy36
Copy link
Contributor

Let clients conveniently cancel the token without any reason.


The cancellation works very nicely. Thanks for the great work, Dennis!

This PR proposes an API change to let clients cancel the token without a reason.

Before:

useEffect(() => {
    const token = new CancellationTokenImpl();
    search(query, filter, token);
    return function () {
        token.cancel('');
    };
}, [search, filter, query]);

After:

useEffect(() => {
    const token = new CancellationTokenImpl();
    search(query, filter, token);
    return function () {
        token.cancel();
    };
}, [search, filter, query]);

Let clients cancel the token without any reason via a convenient way.

Signed-off-by: dankeboy36 <dankeboy36@gmail.com>
it can be inferred from the default empty `string`

Signed-off-by: dankeboy36 <dankeboy36@gmail.com>
@dhuebner
Copy link
Member

@dankeboy36
Thank you for this contribution!
I wonder if we should also make the listeners parameter optional.

Instead of defaulting the reason to an empty string like you proposed public cancel(reason = ''): void make the parameter optional public cancel(reason?: string): void and adjust the callback signature to be callback: (reason?: string) => void . In other words make it more explicit to the listener implementors that the reason might not be provided.

@dankeboy36
Copy link
Contributor Author

I was about to make the requested changes when I saw 6e2df6f. Sorry for the delay, and thanks!

@dhuebner dhuebner merged commit 49d55e7 into TypeFox:main Dec 17, 2024
1 check passed
@dhuebner
Copy link
Member

@dankeboy36
A new v0.5.1 version with optional reason parameter was published.

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