Comment by dminik

Comment by dminik 17 hours ago

1 reply

I think in practice the caller still needs to know.

If I call `a.foo()` but `a` has and is using a stackless coroutine IO but the caller is being executed from a green thread IO then as was said before, I'm hitting UB.

But, I do like that you could skip/mock IO for instance. That's pretty neat.

throwawaymaths 12 hours ago

here is example code. you wont "use the wrong io".

    const VTable = struct {
      f: &fn (*VTable) void,
    };

    const A = struct {
      io: IO,
      v: VTable = .{ .f = &A.uses_io },
      fn uses_io(this: *VTable) void {
        const self: *A = @fieldParentPtr(.v, this);
        self.io.some_io_fn(...);
      }
    };

    const B = struct{v: VTable = .{.f = &void_fn}};
    fn void_fn(_: *VTable) void {}

    pub fn calls_vtable(v: VTable) {
      v.f()
    }