-
-
Notifications
You must be signed in to change notification settings - Fork 308
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
WriteAsync does not use the CancellationToken that is given to it #824
Comments
Hi @minno726, I'm the friendly issue checker. If you think it's fine to make an exception, just ignore this message. Thanks! |
public static async Task<int> SendBytes(this ICharacteristic handle, byte[] data, CancellationToken token)
{
var cs = new TaskCompletionSource();
token.Register(() =>
{
cs.TrySetResult();
});
var t1 = handle.WriteAsync(data, token);
var t = await Task.WhenAny(cs.Task, t1);
if (t == cs.Task)
throw new TimeoutException("Send bytes timeout");
return await t1;
} I use the above method for cancellation. |
Hi @janusw , are you planning on addressing this issue? We have a temp workaround, however would be best if the cancellation would respect the given CancellationToken. And great work on this package btw :) |
To be honest, I'm currently not planning to look into this myself (due to time constraints), but if someone is willing to contribute a PR, I'd be happy to review it and provide support. In general, I'm not actully understanding my maintainer role here as "someone who is responsible for fixing all the bugs", but rather as "someone who is helping others to help themselves". 😄
Thanks, but this compliment certainly does not go to me alone. A lot of people have contributed to this library over the years, and I'm only one of them. It's not "my" package in any way, it's a shared community effort. My advice: If you need something fixed quickly, the best idea is usually to get involved yourself. 😉 |
Steps to reproduce
Call
WriteAsync
by passing aCancellationToken
to it.Before the call completes, cancel the token. This is easiest to do by passing a very small timeout in the constructor for
CancellationTokenSource
.Expected behavior
The operation should be canceled.
Actual behavior
The operation ignores the cancellation.
Configuration
Version of the Plugin: 3.0.0
Platform: Observed on iOS due to #785, but the problem is in shared code.
The source of the problem is here:
dotnet-bluetooth-le/Source/Plugin.BLE/Shared/DescriptorBase.cs
Lines 68 to 76 in b179852
The code does not use the cancellation token that was passed in as a function parameter. See the documentation on how to use cancellation tokens here: https://learn.microsoft.com/en-us/dotnet/standard/threading/cancellation-in-managed-threads, or remove the parameter if cancellation isn't practical to implement.
This is related to #785, since it prevents one workaround for that issue from working.
The text was updated successfully, but these errors were encountered: