diff --git a/examples/news_fetcher.v b/examples/news_fetcher.v index 3cb1a94107..401996bb28 100644 --- a/examples/news_fetcher.v +++ b/examples/news_fetcher.v @@ -18,9 +18,10 @@ struct Story { struct Fetcher { mut: - mu sync.Mutex - ids []int - cursor int + mu sync.Mutex + ids []int + cursor int + list_id int } fn (f mut Fetcher) fetch() { @@ -37,7 +38,11 @@ fn (f mut Fetcher) fetch() { println('failed to decode a story') exit(1) } - println('#$f.cursor) $story.title | $story.url') + f.mu.lock() + f.list_id++ + cursor := f.list_id + f.mu.unlock() + println('#$cursor) $story.title | $story.url') } }