Skip to content

Commit 8a4856c

Browse files
authored
Slightly better example
1 parent 966907e commit 8a4856c

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

README.md

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,15 +29,21 @@ greenlet(Function) -> Function
2929

3030
## Example
3131

32+
Greenlet is most effective when the work being done has relatively small inputs/outputs.
33+
34+
One such example would be fetching a network resource when only a subset of the resulting information is needed:
35+
3236
```js
3337
import greenlet from 'greenlet'
3438

35-
let get = greenlet(async url => {
36-
let res = await fetch(url)
37-
return await res.json()
39+
let getName = greenlet( async username => {
40+
let url = `https://api.github.com/users/${username}`
41+
let res = await fetch(url)
42+
let profile = await res.json()
43+
return profile.name
3844
})
3945

40-
console.log(await get('/foo'))
46+
console.log(await getName('developit'))
4147
```
4248

4349

0 commit comments

Comments
 (0)