Skip to content

Commit ec863a0

Browse files
authored
Fix #33 by documenting intended usage
1 parent ef6ac3d commit ec863a0

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

README.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,16 @@ Accepts an async function with, produces a copy of it that runs within a Web Wor
2626
greenlet(Function) -> Function
2727
```
2828

29+
> ‼️ **Important:** never call greenlet() dynamically. Doing so creates a new Worker thread for every call:
30+
31+
```diff
32+
-const BAD = () => greenlet(x => x)('bad') // creates a new thread on every call
33+
+const fn = greenlet(x => x);
34+
+const GOOD = () => fn('good'); // uses the same thread on every call
35+
```
36+
37+
Since Greenlets can't rely on surrounding scope anyway, it's best to always create them at the "top" of your module.
38+
2939

3040
## Example
3141

0 commit comments

Comments
 (0)