Handles an Interest request.
(
&mut self,
name: &str,
scope: &mut S,
)
| 358 | |
| 359 | /// Handles an Interest request. |
| 360 | pub fn interest<S: Scope<Timestamp = T>>( |
| 361 | &mut self, |
| 362 | name: &str, |
| 363 | scope: &mut S, |
| 364 | ) -> Result<Collection<S, Vec<Value>, isize>, Error> { |
| 365 | // We need to do a `contains_key` here to avoid taking |
| 366 | // a mut ref on context. |
| 367 | if self.context.internal.arrangements.contains_key(name) { |
| 368 | // Rule is already implemented. |
| 369 | let relation = self |
| 370 | .context |
| 371 | .global_arrangement(name) |
| 372 | .unwrap() |
| 373 | .import_named(scope, name) |
| 374 | .as_collection(|tuple, _| tuple.clone()); |
| 375 | |
| 376 | Ok(relation) |
| 377 | } else { |
| 378 | let (mut rel_map, shutdown_handle) = if self.config.enable_optimizer { |
| 379 | implement_neu(name, scope, &mut self.context)? |
| 380 | } else { |
| 381 | implement(name, scope, &mut self.context)? |
| 382 | }; |
| 383 | |
| 384 | // @TODO when do we actually want to register result traces for re-use? |
| 385 | // for (name, relation) in rel_map.into_iter() { |
| 386 | // let trace = relation.map(|t| (t, ())).arrange_named(name).trace; |
| 387 | // self.context.register_arrangement(name, config, trace); |
| 388 | // } |
| 389 | |
| 390 | match rel_map.remove(name) { |
| 391 | None => Err(Error::fault(format!( |
| 392 | "Relation of interest ({}) wasn't actually implemented.", |
| 393 | name |
| 394 | ))), |
| 395 | Some(relation) => { |
| 396 | self.shutdown_handles |
| 397 | .insert(name.to_string(), shutdown_handle); |
| 398 | |
| 399 | Ok(relation) |
| 400 | } |
| 401 | } |
| 402 | } |
| 403 | } |
| 404 | |
| 405 | /// Handle a Register request. |
| 406 | pub fn register(&mut self, req: Register) -> Result<(), Error> { |