Skip to content

Commit 68d630f

Browse files
committed
cran check
1 parent 4c9d01b commit 68d630f

File tree

8 files changed

+738
-393
lines changed

8 files changed

+738
-393
lines changed

NEWS.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# async 0.3.2
22

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`.
44
* New vignette `vignette("spider")` shows how to control several concurrent downloads using `async`/`await`.
55
* Improved memory usage: Coroutines which exit drop references to their evaluation environments, allowing them to be garbage collected.
66

R/channel.R

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,7 @@ deque <- function(len=64) {
8989
#' and other processes that yield a sequence of values over time.
9090
#'
9191
#' `channel` is an S3 method and will attempt to convert the argument
92-
#' `obj` into a channel object according to its class. In particular
93-
#' [connection] objects will be wrapped with a connection.
92+
#' `obj` into a channel object according to its class.
9493
#'
9594
#' The friendly way to obtain values from a channel is to use
9695
#' `awaitNext` or `for` loops within an [async] or [stream] coroutine.
@@ -398,9 +397,10 @@ combine <- function(...) {
398397
})
399398
}
400399

400+
# (not ready for prime time...)
401401
# The channel method for connections wraps a connection object
402402
# (which should be opened in non-blocking mode).
403-
channel.connection <- function(obj, ...,
403+
channel_connection <- function(obj, ...,
404404
read = {
405405
if (summary(obj)$text == "text")
406406
c("lines", "char")

R/util.R

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -288,16 +288,12 @@ s3_register <- function(generic, class, method = NULL) {
288288
if (exists(generic, envir)) {
289289
registerS3method(generic, class, method_fn, envir = envir)
290290
} else if (identical(Sys.getenv("NOT_CRAN"), "true")) {
291-
warn <- .rlang_s3_register_compat("warn")
292-
293-
warn(c(
294-
sprintf(
295-
"Can't find generic `%s` in package %s to register S3 method.",
296-
generic,
297-
package
298-
),
299-
"i" = "This message is only shown to developers using devtools.",
300-
"i" = sprintf("Do you need to update %s to the latest version?", package)
291+
# This message is only shown to developers using devtools.
292+
# Do you need to update %s to the latest version?
293+
warning(sprintf(
294+
"Can't find generic `%s` in package %s to register S3 method.",
295+
generic,
296+
package
301297
))
302298
}
303299
}

ctz.svg

Lines changed: 0 additions & 1 deletion
This file was deleted.

ctz.svg

Lines changed: 291 additions & 0 deletions
Loading

man/channel.Rd

Lines changed: 1 addition & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vignettes/file_dataset.svg

Lines changed: 422 additions & 366 deletions
Loading

vignettes/language.Rmd

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -135,16 +135,18 @@ file_dataset <- async({
135135
tryCatch(read_json(filename), error=goto("txt"))
136136
},
137137
"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))
142142
}
143143
)
144144
})
145145
```
146146

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.
148150

149151
### What's under the hood? Coroutines are state machines, which are graphs
150152

vignettes/spider.Rmd

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ This would amount to some restructuring of our program. But rather than rewrite
142142

143143
## Wiring up `curl` to `promises`
144144

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.
146146

147147
[promises]: https://rstudio.github.io/promises/
148148

@@ -183,9 +183,9 @@ R's event loop runs while R is otherwise idle or awaiting input. R enters the ev
183183

184184
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.
185185

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`:
187187

188-
[later]: https://github.com/r-lib/later
188+
[later]: https://r-lib.github.io/later/
189189

190190
```{R}
191191
poll_curl <- function() {
@@ -204,7 +204,7 @@ The global flag `curl_is_active` is used to keep from cluttering up the event lo
204204

205205
## An Asynchronous Spider
206206

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:
208208

209209
```{R}
210210
library(async)
@@ -269,7 +269,9 @@ For the most part, this is almost identical to the non-asynchronous version. In
269269

270270
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.
271271

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]:
273275

274276
### A single thread, dividing attention between tasks
275277

0 commit comments

Comments
 (0)