MCPcopy Index your code
hub / github.com/RustPython/RustPython / add_done_callback

Method add_done_callback

crates/stdlib/src/_asyncio.rs:333–362  ·  view source on GitHub ↗
(
            zelf: PyRef<Self>,
            args: AddDoneCallbackArgs,
            vm: &VirtualMachine,
        )

Source from the content-addressed store, hash-verified

331
332 #[pymethod]
333 fn add_done_callback(
334 zelf: PyRef<Self>,
335 args: AddDoneCallbackArgs,
336 vm: &VirtualMachine,
337 ) -> PyResult<()> {
338 if zelf.fut_loop.read().is_none() {
339 return Err(vm.new_runtime_error("Future object is not initialized."));
340 }
341 let ctx = match args.context.flatten() {
342 Some(c) => c,
343 None => get_copy_context(vm)?,
344 };
345
346 if zelf.fut_state.load() != FutureState::Pending {
347 Self::call_soon_with_context(&zelf, args.func, Some(ctx), vm)?;
348 } else if zelf.fut_callback0.read().is_none() {
349 *zelf.fut_callback0.write() = Some(args.func);
350 *zelf.fut_context0.write() = Some(ctx);
351 } else {
352 let tuple = vm.ctx.new_tuple(vec![args.func, ctx]);
353 let mut callbacks = zelf.fut_callbacks.write();
354 if callbacks.is_none() {
355 *callbacks = Some(vm.ctx.new_list(vec![tuple.into()]).into());
356 } else {
357 let list = callbacks.as_ref().unwrap();
358 vm.call_method(list, "append", (tuple,))?;
359 }
360 }
361 Ok(())
362 }
363
364 #[pymethod]
365 fn remove_done_callback(&self, func: PyObjectRef, vm: &VirtualMachine) -> PyResult<usize> {

Callers

nothing calls this directly

Calls 13

get_copy_contextFunction · 0.85
new_listMethod · 0.80
ErrClass · 0.50
SomeClass · 0.50
is_noneMethod · 0.45
readMethod · 0.45
flattenMethod · 0.45
loadMethod · 0.45
writeMethod · 0.45
new_tupleMethod · 0.45
unwrapMethod · 0.45
as_refMethod · 0.45

Tested by

no test coverage detected