Std.Sync.swap
1 declaration
fn
swap: &Std.Sync.Cell[T] -> T -> Result[T, Std.Sync.SyncError]This is a callable function.
What it does
Replace what a cell holds and answer what it held, in one step nothing can
come between.
This is the only write, because it is the only one that composes. A read
followed by a write is two steps, and another thread can act between them:
a counter built that way loses additions, and loses them only under the
load that makes the loss hardest to reproduce. A caller that needs to
decide what to write from what is there wants Counter or a lock.
Read the signature
- The text after the name is the type checked by Pudu.
- Read arrows from left to right: inputs come first, and the final type is returned.
- & borrows a value for this call instead of moving or copying it.
- Names inside [ ] are type arguments, such as the item type held by a collection.
- Result makes success and recoverable failure part of the function's type.
