Skip to content

Commit

Permalink
Push promises method performance (shikokuchuo#161)
Browse files Browse the repository at this point in the history
* use underlying promises functions

* use .unresolved()

* advance version
  • Loading branch information
shikokuchuo authored Oct 7, 2024
1 parent ab8dc01 commit 12d26e0
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 12 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package: mirai
Type: Package
Title: Minimalist Async Evaluation Framework for R
Version: 1.2.0.9029
Version: 1.2.0.9030
Description: Designed for simplicity, a 'mirai' evaluates an R expression
asynchronously in a parallel process, locally or distributed over the
network, with the result automatically available upon completion. Modern
Expand Down
2 changes: 1 addition & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# mirai 1.2.0.9029 (development)
# mirai 1.2.0.9030 (development)

#### New Features

Expand Down
21 changes: 11 additions & 10 deletions R/promises.R
Original file line number Diff line number Diff line change
Expand Up @@ -68,22 +68,23 @@ as.promise.mirai <- function(x) {

if (is.null(promise)) {

if (unresolved(x)) {
promise <- promises::then(
promises::promise(
function(resolve, reject) .keep(x, environment())
),
promise <- if (.unresolved(x)) {
promises::promise(
function(resolve, reject) .keep(x, environment())
)$then(
onFulfilled = function(value)
if (is_error_value(value) && !is_mirai_interrupt(value))
stop(if (is_mirai_error(value)) value else nng_error(value)) else
value
)

} else {
value <- .subset2(x, "value")
promise <- if (is_error_value(value) && !is_mirai_interrupt(value))
promises::promise_reject(if (is_mirai_error(value)) value else nng_error(value)) else
promises::promise_resolve(value)
value <- collect_aio(x)
promises::promise(
function(resolve, reject)
if (is_error_value(value) && !is_mirai_interrupt(value))
reject(value) else
resolve(value)
)
}

assign("promise", promise, x)
Expand Down

0 comments on commit 12d26e0

Please sign in to comment.