Created
January 20, 2017 21:10
-
-
Save mwdchang/0c62bbec437ebf2c87e76144e341dfb2 to your computer and use it in GitHub Desktop.
Background R processing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(parallel) | |
library(background) | |
cache = new.env(); | |
cache[["t"]] <- "f" | |
#* @get /set | |
set <- function() { | |
parallelFn <- function() { | |
Sys.sleep(5) | |
r <- NULL | |
r["key"] <- "test" | |
r["val"] <- "Hello world" | |
r | |
} | |
p <- parallel::mcparallel( parallelFn() ) | |
async.add(p$fd[1], function(h, p) { | |
async.rm(h) | |
print(" Inside async") | |
result <- parallel::mccollect(p) | |
print(" ") | |
myResult <-result[[1]] | |
myResult | |
print(" Caching...") | |
cache[[myResult["key"]]] <- myResult["key"] | |
}, p) | |
return("UUID of something") | |
} | |
#* @get /get | |
get <- function() { | |
print("Get") | |
print(cache[["t"]]) | |
print(cache[["test"]]) | |
return(cache[["test"]]) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment