Last active
October 2, 2019 15:22
-
-
Save mpkocher/66df08f32a3fbe4c8cf2 to your computer and use it in GitHub Desktop.
Registry Example
This file contains hidden or 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(methods) | |
#' @export | |
ExampleRegistry <- setRefClass("ExampleRegistry", fields=list(namespace="character", driver="character", rtcRunners="list", toolContracts="list")) | |
registerFunc <- function(r, funcId, func) { | |
r$rtcRunners[[funcId]] <- func | |
return(r) | |
} | |
registryRunner <- function(r, funcId, name) { | |
f <- r$rtcRunners[[funcId]] | |
result <- f(name) | |
return(result) | |
} | |
exampleFunc <- function(name) { | |
print("Running exampleFunc") | |
print(paste("User name ", name)) | |
return(0) | |
} | |
exampleHello <- function(name) { | |
print("Runing hello func") | |
print(paste("My Name is ", name)) | |
return(0) | |
} | |
exampleRegistry <- function() { | |
r <- ExampleRegistry$new(namespace = "my_tool", driver= "driver-base", rtcRunners = list(), toolContracts = list()) | |
registerFunc(r, "f1", exampleFunc) | |
registerFunc(r, "f2", exampleHello) | |
return(r) | |
} | |
main <- function() { | |
r <- exampleRegistry() | |
print(r) | |
result <- registryRunner(r, "f1", "Func1 Ralph") | |
print(result) | |
result <- registryRunner(r, "f2", "Func2 Treefort") | |
print(result) | |
return(0) | |
} | |
q(status = main()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment