Skip to content

Commit

Permalink
Update to tuple spec (#2227)
Browse files Browse the repository at this point in the history
* Use tuple spec instead of deprecated worker()

* Update multi-consumer example
  • Loading branch information
joeapearson committed Mar 14, 2020
1 parent a771275 commit 09b2834
Showing 1 changed file with 17 additions and 11 deletions.
28 changes: 17 additions & 11 deletions en/lessons/advanced/gen-stage.md
@@ -1,5 +1,5 @@
---
version: 1.0.2
version: 1.1.0
title: GenStage
---

Expand Down Expand Up @@ -67,7 +67,7 @@ Let's update our dependencies in `mix.exs` to include `gen_stage`:
```elixir
defp deps do
[
{:gen_stage, "~> 0.11"},
{:gen_stage, "~> 1.0.0"},
]
end
```
Expand Down Expand Up @@ -136,7 +136,7 @@ defmodule GenstageExample.ProducerConsumer do

require Integer

def start_link do
def start_link(_initial) do
GenStage.start_link(__MODULE__, :state_doesnt_matter, name: __MODULE__)
end

Expand Down Expand Up @@ -177,7 +177,7 @@ Since consumers and producer-consumers are so similar our code won't look much d
defmodule GenstageExample.Consumer do
use GenStage

def start_link do
def start_link(_initial) do
GenStage.start_link(__MODULE__, :state_doesnt_matter)
end

Expand Down Expand Up @@ -209,9 +209,9 @@ def start(_type, _args) do
import Supervisor.Spec, warn: false

children = [
worker(GenstageExample.Producer, [0]),
worker(GenstageExample.ProducerConsumer, []),
worker(GenstageExample.Consumer, [])
{GenstageExample.Producer, 0},
{GenstageExample.ProducerConsumer, []},
{GenstageExample.Consumer, []}
]

opts = [strategy: :one_for_one, name: GenstageExample.Supervisor]
Expand Down Expand Up @@ -247,10 +247,16 @@ Let's make some adjustments for multiple workers by modifying `lib/genstage_exam

```elixir
children = [
worker(GenstageExample.Producer, [0]),
worker(GenstageExample.ProducerConsumer, []),
worker(GenstageExample.Consumer, [], id: 1),
worker(GenstageExample.Consumer, [], id: 2)
{GenstageExample.Producer, 0},
{GenstageExample.ProducerConsumer, []},
%{
id: 1,
start: {GenstageExample.Consumer, :start_link, [[]]}
},
%{
id: 2,
start: {GenstageExample.Consumer, :start_link, [[]]}
},
]
```

Expand Down

0 comments on commit 09b2834

Please sign in to comment.