Skip to content

Commit

Permalink
IEnumerable execution is deferred final revision
Browse files Browse the repository at this point in the history
  • Loading branch information
jai-dewani committed Aug 30, 2024
1 parent bde6272 commit 1a6e84b
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions content/blog/deffered-ienumerable/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,9 @@ foreach (var value in waitingParagraph)
Console.WriteLine($"Time taken - {stopwatch.Elapsed}"); // Around 00:00:02.6724506
```

In this example, even though we're using `Thread.Sleep` in the `.Select` projection, the processing isn't executed until we start iterating over all the elements one by one. Hence the stopwatch shows the execution time of looping over the elements takes more than 2 seconds but actually this is where the `.Select` command is being executed when each element is requested.
In this example, even though we're using `Thread.Sleep` within the `.Select` projection, the processing isn't executed until we start iterating over all the elements one by one. As a result, the stopwatch shows that looping over the elements takes more than 2 seconds, but this is actually the time spent executing the `.Select` command for each element as it is requested.

A fun usecase of this could be, creating a typing awareness animation by introducing randomness in the `Thread.Sleep` time to achieve the desired effect.
A fun use case for this could be creating a typing awareness animation by introducing randomness into the `Thread.Sleep` time to achieve the desired effect.

![typing awareness animation](./media/WindowsTerminal_U4dYkwMC6t.gif)

Expand Down

0 comments on commit 1a6e84b

Please sign in to comment.