-
-
Notifications
You must be signed in to change notification settings - Fork 574
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(core): improve loop function (#952)
- Loading branch information
1 parent
51d8cf0
commit 66c18bb
Showing
3 changed files
with
69 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
Make sure to use `yield` or `spawn()` to execute the loop concurrently in a | ||
separate thread: | ||
|
||
```ts | ||
// wrong ✗ | ||
// prettier-ignore | ||
yield* loop(() => rect().opacity(0).opacity(1, 1)); | ||
// correct ✓ | ||
yield loop(() => rect().opacity(0).opacity(1, 1)); | ||
// correct ✓ | ||
spawn(loop(() => rect().opacity(0).opacity(1, 1))); | ||
``` | ||
|
||
If you want to execute the loop a finite number of times, specify the iteration | ||
count as the first argument: | ||
|
||
```ts | ||
// prettier-ignore | ||
yield* loop(10, () => rect().opacity(0).opacity(1, 1)); | ||
// ^ iteration count | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters