Skip to content
This repository was archived by the owner on Jun 16, 2025. It is now read-only.

Commit 85290d2

Browse files
committed
Add "Cancellable by design" principle to documentation; clarify coroutine lifetime management
1 parent eec7c7e commit 85290d2

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

basic.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,26 @@ All functions, classes, and constants defined in this **RFC** are located in the
270270
Extensions for **Scheduler/Reactor** are allowed to extend this namespace with functions and classes,
271271
provided that they are directly related to concurrency functionality.
272272

273+
### Cancellable by design
274+
275+
This RFC is based on the principle of **"Cancellable by design"**, which can be described as follows:
276+
277+
> By default, coroutines **should be** designed in such a way that their
278+
> cancellation at any moment does not compromise data integrity.
279+
280+
> Coroutines launched without a defined `Scope` or lifetime **must** adhere to the "Cancellable by design" principle.
281+
282+
> If a coroutine’s lifetime needs to be controlled — it **MUST** be done **EXPLICITLY**!
283+
284+
In practice, this means that if a coroutine is created using the expression `spawn <callable>`,
285+
the developer treats it as non-critical in terms of data integrity.
286+
If the developer needs to manage the coroutine’s lifetime, they will use the expression `spawn with`.
287+
In other words, the developer must take extra steps to explicitly extend the coroutine's lifetime.
288+
289+
The **Cancellable by design** principle works especially well for server-side applications,
290+
but it can conflict with the principles of **structured concurrency**.
291+
This **RFC** proposes a balance between both approaches.
292+
273293
### Coroutine
274294

275295
> A `Coroutine` is an `execution container`, transparent to the code,

0 commit comments

Comments
 (0)