HI
I am using c# driver(NetCore) with CancellationToken
When I am canceling a request the canceling take few second and not immediately (~10 sec)
any idea ?
Hi,
Would you please share how you call CancellationToken in your API?
If you could incorporate my code would be very helpful and appreciated.
public class UserRepository : IUserRepository {
private readonly CancellationToken _cancellationToken;
// constructor - dependency injection
public UserRepository(IMongoClient client, IMongoDbSettings dbSettings, ITokenService tokenService) {
var database = client.GetDatabase(dbSettings.DatabaseName);
_collection = database.GetCollection<AppUser>(_collectionName);
_tokenService = tokenService;
_cancellationToken = new CancellationToken();
}
public async Task<UserDto?> GetUser(string userId) {
var user = await _collection.Find<AppUser>(user => user.Id == userId).FirstOrDefaultAsync();
return new UserDto {
//some code
};
}
}