You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: NEWS.md
+1-1Lines changed: 1 addition & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -1,6 +1,6 @@
1
1
# async 0.3.2
2
2
3
-
* The `iteror` class has been extracted to a new package [`iterors`](http://github.com/crowding/iterors), which also includes ports of all functionality from `iterators`, `itertools`, and `itertools2`.
3
+
* The `iteror` class has been extracted to a new package [`iterors`](https://github.com/crowding/iterors), which also includes ports of all functionality from `iterators`, `itertools`, and `itertools2`.
4
4
* New vignette `vignette("spider")` shows how to control several concurrent downloads using `async`/`await`.
5
5
* Improved memory usage: Coroutines which exit drop references to their evaluation environments, allowing them to be garbage collected.
Copy file name to clipboardExpand all lines: vignettes/language.Rmd
+7-5Lines changed: 7 additions & 5 deletions
Original file line number
Diff line number
Diff line change
@@ -135,16 +135,18 @@ file_dataset <- async({
135
135
tryCatch(read_json(filename), error=goto("txt"))
136
136
},
137
137
"zip"= {
138
-
unzipped <- unzip(filename)
139
-
on.exit(unlink(unzipped))
140
-
unzip(filename)
141
-
goto() # i.e. run getExtension on the new filename
138
+
unzipped <- unzip_async(filename) |> await()
139
+
filename <- unzipped
140
+
on.exit(unlink(unzipped))
141
+
goto(getExtension(unzipped))
142
142
}
143
143
)
144
144
})
145
145
```
146
146
147
-
Here, if there is an error in reading a `.csv` or `.json` file we re-try ingesting it as a text file; on encountering a `zip` file we unzip it and try again with the new filename. If a `goto` appears inside of a `try(..., finally={...})` call, which is itself inside a branch, the `finally` clause will be executed _before_ jumping to the new branch.
147
+
Here, if there is an error in reading a `.csv` or `.json` file we re-try ingesting it as a text file; on encountering a `zip` file we unzip it and try again with the new filename.
148
+
149
+
Note that if a `goto` appears inside of a `try(..., finally={...})` call, which is itself inside a branch, the `finally` clause will be executed _before_ jumping to the new branch.
148
150
149
151
### What's under the hood? Coroutines are state machines, which are graphs
Copy file name to clipboardExpand all lines: vignettes/spider.Rmd
+7-5Lines changed: 7 additions & 5 deletions
Original file line number
Diff line number
Diff line change
@@ -142,7 +142,7 @@ This would amount to some restructuring of our program. But rather than rewrite
142
142
143
143
## Wiring up `curl` to `promises`
144
144
145
-
Many things with asynchronous interfaces have their own ad-hoc APIs for calling them; here `libcurl` uses `curl_fetch_multi` and `multi_run`. The `async` package relies on the `promise` class, from package "[promises][]," as a unifying abstraction for asynchronous requests. To use an ad hoc asynchronous API with the `async` package, the first step is often to make a shim presenting that that API in terms of promises.
145
+
Lots of software supporting asynchronous processing does so with an ad-hoc API; here `libcurl` uses `curl_fetch_multi` and `multi_run`. The `async` package relies on the `promise` class, from package "[promises][]," as a unifying abstraction for asynchronous requests. To use an ad hoc asynchronous API with the `async` package, the first step is often to make a shim presenting that API in terms of promises.
146
146
147
147
[promises]: https://rstudio.github.io/promises/
148
148
@@ -183,9 +183,9 @@ R's event loop runs while R is otherwise idle or awaiting input. R enters the ev
183
183
184
184
For example, the builtin HTTP server `help.start()` uses the event loop; when it is active the event loop will periodically check for and handle incoming HTTP connections. The Shiny web server also does this. When a graphics window is open, the event loop is where R checks for mouse clicks or window resizes. And the `promises` package, and by extension `async` uses the event loop to schedule processing.
185
185
186
-
The [later]() package provides a simple interface for us to to use R's event loop to check in things. Above, in `curl_fetch_async` we called `later(poll_curl)`, which arranges for `poll_curl` to be called on the next run through R's event loop. Here is the definition of `poll_curl`:
186
+
The [later][] package provides a simple interface for us to to use R's event loop to check in things. Above, in `curl_fetch_async` we called `later(poll_curl)`, which arranges for `poll_curl` to be called on the next run through R's event loop. Here is the definition of `poll_curl`:
187
187
188
-
[later]: https://github.com/r-lib/later
188
+
[later]: https://r-lib.github.io/later/
189
189
190
190
```{R}
191
191
poll_curl <- function() {
@@ -204,7 +204,7 @@ The global flag `curl_is_active` is used to keep from cluttering up the event lo
204
204
205
205
## An Asynchronous Spider
206
206
207
-
Interfacing `curl` with `async` was the hard part. Now that this is accomplished, making our spider asynchronous is simple. Here is the asynchronous version of our web spider:
207
+
Interfacing `curl` with `async` was the hard part. Now that this is accomplished, we can make our web spider operate concurrently. Here is the asynchronous version of our web spider:
208
208
209
209
```{R}
210
210
library(async)
@@ -269,7 +269,9 @@ For the most part, this is almost identical to the non-asynchronous version. In
269
269
270
270
Wrapping a function definition in `async` creates an async function. This is effectively a function that can pause and resume. Calling an async function does not execute the function immediately, but returns a promise, that will be resolved with the function's eventual return value. The function will actually begin executing the next time R runs the event loop.
271
271
272
-
When an async function reaches a call to `await(x)`, it pauses, allowing R's event loop to continue. The argument to `await` should be a promise. After that promise resolves, the awaiting function will then resume with that value.
272
+
When an async function reaches a call to `await(x)`, it pauses, allowing R's event loop to continue. The argument to `await` should be a [promise][]. After that promise resolves, the awaiting function will then resume with that value.
273
+
274
+
[promise]:
273
275
274
276
### A single thread, dividing attention between tasks
0 commit comments