Skip to content

Commit

Permalink
Merge pull request #50 from rstudio/wch-fix-promise-all-null
Browse files Browse the repository at this point in the history
Fix NULL handling in promise_all()
  • Loading branch information
wch authored Jul 25, 2019
2 parents 852e9be + d22f17b commit cc377de
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 3 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package: promises
Type: Package
Title: Abstractions for Promise-Based Asynchronous Programming
Version: 1.0.1.9000
Version: 1.0.1.9001
Authors@R: c(
person("Joe", "Cheng", email = "joe@rstudio.com", role = c("aut", "cre")),
person("RStudio", role = c("cph", "fnd"))
Expand Down
7 changes: 6 additions & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
promises 1.0.1.9001
================

* Fixed [#49](https://github.com/rstudio/promises/issues/49): `promise_all()` previously did not handle `NULL` values correctly. ([#50](https://github.com/rstudio/promises/pull/50))

promises 1.0.1
================

- Initial CRAN release
* Initial CRAN release
4 changes: 3 additions & 1 deletion R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,9 @@ promise_all <- function(..., .list = NULL) {
then(.list[[key]],
onFulfilled = function(value) {
# Save the result so we can return it to the user.
results[[key]] <<- value
# This weird assignment is similar to `results[[key]] <- value`, except
# that it handles NULL values correctly.
results[key] <<- list(value)

# Record the fact that the promise was completed.
done[[key]] <<- TRUE
Expand Down
10 changes: 10 additions & 0 deletions tests/testthat/test-combining.R
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,14 @@ describe("promise_all", {
x <- promise_all(.list = list(a=a, b=b, c=c))
expect_identical(extract(x), list(a=1, b=2, c=3))
})

it("Handles NULLs correctly", {
x <- promise_all(promise_resolve(NULL), promise_resolve(NULL),
promise_resolve(NULL))
expect_identical(extract(x), list(NULL, NULL, NULL))

x <- promise_all(a = promise_resolve(NULL), b = promise_resolve(NULL),
c = promise_resolve(NULL))
expect_identical(extract(x), list(a = NULL, b = NULL, c = NULL))
})
})

0 comments on commit cc377de

Please sign in to comment.