cancellation
Skill1 starsChanged 7 days agoMITView on GitHub
How cancellation tokens flow from the caller through Mediator, handlers and repositories to EF Core, and how tests prove they are passed on. Use when writing any async method, endpoint, handler or repository call.
In this repository40 other files it gives its agents.
- AGENTS.mdAGENTS.md
- CLAUDE.mdCLAUDE.md
- add-a-use-caseSkill
- api-conventionsSkill
- branches-and-pull-requestsSkill
- ci-for-your-solutionSkill
- ci-pipelineSkill
- clean-architecture-layersSkill
- configuration-and-environmentsSkill
- coverageSkill
- csharp-house-styleSkill
- data-access-ef-coreSkill
- database-migrationsSkill
- docker-and-composeSkill
- docs-and-voiceSkill
- errors-and-exceptionsSkill
- expose-a-use-caseSkill
- family-syncSkill
- health-checksSkill
- integration-testsSkill
- json-serializationSkill
- mapping-with-mapperlySkill
- mcp-inspectorSkill
- mediatorSkill
- optional-token-authSkill
- packages-and-dependenciesSkill
- pagingSkill
- presentation-integration-testsSkill
- releasesSkill
- sample-dataSkill
- security-findingsSkill
- serilogSkill
- telemetrySkill
- template-authoringSkill
- test-designSkill
- time-providerSkill
- unit-testsSkill
- validationSkill
- writing-a-skillSkill
- xml-docs-and-openapiSkill
The file
We split this skill into the rules it gives an agent
4 rules. About 0 are common, 2 are distinctive, and 2 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈2
Distinctive · estimate
This author's own choices. Worth a look.
2
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 12
Every async call that can be cancelled is given the token of the request that started it, all the way down to the database.
- Very specific: line 22
Add CancellationToken cancellationToken as the last parameter of any new async method.
- Very specific: line 39
Use CancellationToken.None or default outside tests.
- Distinctive: line 40
Leave the token out of one call in a chain.
≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Cancellation
The rule
Every async call that can be cancelled is given the token of the request that started it, all the way down to the database. When a caller goes away, the work stops.
| Layer | Where the token comes from |
| Presentation | The framework: an endpoint or tool parameter, HttpContext.RequestAborted, or (in Lambda) a source built from context.RemainingTime |
| Application | Handle(request, cancellationToken) |
| Infrastructure | The last parameter of every repository method, passed to every EF Core ...Async call |
Steps
- Add
CancellationToken cancellationTokenas the last parameter of any new async method. - Pass it to
sender.Send(request, cancellationToken), to every repository call, and to every EF Core method (ToListAsync,CountAsync,ExecuteUpdateAsync,SaveChangesAsync). - In tests, create a real token and assert it's the one that reached the mock (
unit-tests):
using var tokenSource = new CancellationTokenSource();
var token = tokenSource.Token;
// Act
var result = await handler.Handle(command, token);
// Assert
_ = await reviewsRepository.Received(1).UpdateReview(command.Id, command.Stars, command.Text, token);Don't
- Use
CancellationToken.Noneordefaultoutside tests. - Leave the token out of one call in a chain. Every hop needs it.
- Make the token optional (
= default) on an interface method.
Check
dotnet build
dotnet testDoes it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

