MCPcopy Create free account
hub / github.com/MegEngine/MegFlow / new

Method new

flow-rs/src/sandbox.rs:46–136  ·  view source on GitHub ↗
(ty: &str, args: toml::value::Table, res: Vec<String>)

Source from the content-addressed store, hash-verified

44 Sandbox::new(ty, args, vec![])
45 }
46 pub fn new(ty: &str, args: toml::value::Table, res: Vec<String>) -> Result<Sandbox> {
47 let local_key = crate::LOCAL_KEY.fetch_add(1, Ordering::Relaxed);
48 crate::registry::initialize(local_key);
49
50 let config = interlayer::Node {
51 entity: interlayer::Entity {
52 name: format!("sandbox-{}", ty),
53 ty: vec![ty.to_owned()],
54 args,
55 },
56 res,
57 cloned: None,
58 inputs: Default::default(),
59 outputs: Default::default(),
60 is_dyn: false,
61 is_shared: false,
62 };
63 let inputs_name: Vec<String> = inputs(local_key, ty)?.into_iter().collect();
64 let outputs_name: Vec<String> = outputs(local_key, ty)?.into_iter().collect();
65 let mut inputs = HashMap::new();
66 let mut outputs = HashMap::new();
67 let mut actor = load_static(local_key, &config)?.pop().unwrap();
68 let mut broker = Broker::new();
69
70 if inputs_name.iter().any(|x| x.starts_with("dyn")) {
71 ONCE_INIT_I.call_once(|| {
72 graph_register(local_key, "NoopProducer", "out");
73 });
74 }
75
76 if outputs_name.iter().any(|x| x.starts_with("dyn")) {
77 ONCE_INIT_O.call_once(|| {
78 graph_register(local_key, "NoopConsumer", "inp");
79 });
80 }
81
82 for input in &inputs_name {
83 if !input.starts_with("dyn") {
84 let chan = ChannelStorage::unbound();
85 actor.set_port(input, Some(0), &chan);
86 let mut input = input.as_str();
87 if input.starts_with('[') || input.starts_with('{') {
88 input = &input[1..input.len() - 1];
89 }
90 inputs.insert(input.to_owned(), chan);
91 } else {
92 let client = broker.subscribe("_NoopProducer_".to_owned());
93 actor.set_port_dynamic(
94 input,
95 crate::node::DynPortsConfig {
96 local_key,
97 target: "out".to_owned(),
98 cap: 16,
99 brokers: vec![client],
100 args: Default::default(),
101 },
102 );
103 }

Callers

nothing calls this directly

Calls 11

initializeFunction · 0.85
load_staticFunction · 0.85
graph_registerFunction · 0.85
popMethod · 0.80
insertMethod · 0.80
subscribeMethod · 0.80
inputsFunction · 0.50
outputsFunction · 0.50
set_portMethod · 0.45
lenMethod · 0.45
set_port_dynamicMethod · 0.45

Tested by

no test coverage detected