Heyho, I am trying to run a {.nimcall.} proc that is stored inside the field of 
an object on another thread using taskpool/weave_io or whatever other 
functional threadpool we have.

I'm absolutely failing on getting it to work however.

Code-wise, this roughly represents what I want:
    
    
    import weave_io
    import std/isolation
    
    type Actor = ref object
      field1: int
      field2: int
      command: proc(x,y: int)
    
    proc runner(x, y: int) {.raises: [], gcsafe.} =
      echo x, y
    
    let actor = Actor(field1: 3, field2: 4, command: runner)
    proc run(actor: Actor) =
      actor.command(actor.field1, actor.field2)
    
    var tp: Threadpool = Threadpool.new()
    tp.spawn run(actor)
    tp.shutdown()
    
    
    Run

field1 and 2 down the line will turn `Table[int, pointer]` but that is for 
another time. For now I simply want this to execute.

The problem is that regardless of how I slice it, I can't find any way to 
execute a proc this way:

  * With `tp.spawn actor.command(actor.field1, actor.field2)` the spawn macro 
of both taskpool and weave_io (both having the exact same issue) explodes, 
unable to understand this syntax
  * With the above example it complains that `run` can throw an exception, but 
even if you add a try-catch you can't make it safe enough because passing in 
actor isn't safe. Even if run instead takes in `Isolated[Actor]` (because at 
this point I do not care, I'll deep copy everything if I have to) it is 
impossible, because to extract from an `Isolated[T]` it must be `var` and it is 
impossible to capture a `var isolatedActor` in weaves spawn macro because that 
isn't safe



The only alternative that I'm aware of is malebolgia but that shares the same 
problems at first glance - It requires the parameters to be isolatable for 
safety reasons, the problem here is that I know its safe but I can't circumvent 
these precautions.

Reply via email to