-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfuture.R
43 lines (38 loc) · 787 Bytes
/
future.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
library(future)
plan(multiprocess)
#* @get /
api_version <- function(){
version <- list(Version = "0.0.1",
Comments = "use future to handle api calls asynchronously")
return(version)
}
#* @get /a
a <- function(){
process_a %<-% {
Sys.sleep(2)
current_pid <- Sys.getpid()
return(current_pid)
}
output <- list("Handled in pid: " = process_a)
output
}
#* @get /b
b <- function(){
process_b %<-% {
Sys.sleep(2)
current_pid <- Sys.getpid()
return(current_pid)
}
output <- list("Handled in pid: " = process_b)
output
}
#* @get /c
c <- function(){
process_c %<-% {
Sys.sleep(2)
current_pid <- Sys.getpid()
return(current_pid)
}
output <- list("Handled in pid: " = process_c)
output
}