Skip to content

Commit 663887a

Browse files
author
José Valim
committed
Improve docs for cancel/3, closes #222
1 parent ca131db commit 663887a

File tree

1 file changed

+19
-7
lines changed

1 file changed

+19
-7
lines changed

lib/gen_stage.ex

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1411,13 +1411,25 @@ defmodule GenStage do
14111411
@doc """
14121412
Cancels the given subscription on the producer.
14131413
1414-
Once the producer receives the request, a confirmation
1415-
may be forwarded to the consumer (although there is no
1416-
guarantee as the producer may crash for unrelated reasons
1417-
before). This is an asynchronous request.
1418-
1419-
It accepts the same options as `Process.send/3`, and returns the same value as
1420-
`Process.send/3`.
1414+
The second argument is the cancellation reason. Once the
1415+
producer receives the request, a confirmation may be
1416+
forwarded to the consumer (although there is no guarantee
1417+
as the producer may crash for unrelated reasons before).
1418+
The consumer will react to the cancellation according to
1419+
the `:cancel` option given when subscribing. For example:
1420+
1421+
GenStage.cancel({pid, subscription}, :shutdown)
1422+
1423+
will cause the consumer to crash if the `:cancel` given
1424+
when subscribing is `:permanent` (the default) but it
1425+
won't cause a crash in other modes. See the options in
1426+
`sync_subscribe/3` for more information.
1427+
1428+
The `cancel` operation is an asynchronous request. The
1429+
third argument are same options as `Process.send/3`,
1430+
allowing you to pass `:noconnect` or `:nosuspend` which
1431+
is useful when working across nodes. This function returns
1432+
the same value as `Process.send/3`.
14211433
"""
14221434
@spec cancel(from, term, [:noconnect | :nosuspend]) :: :ok | :noconnect | :nosuspend
14231435
def cancel({pid, ref} = _producer_subscription, reason, opts \\ []) do

0 commit comments

Comments
 (0)