As far as I know ORC made it possible to share global variables. I'm creating 
networking service, which maintains stateful Session object in memory. Is that 
possible to do with ORC? I'm using `-mm:orc` switch, but it still complains 
that procs not `gcsafe`.
    
    
    import std/[httpcore, asynchttpserver, asyncnet, tables, asyncdispatch]
    
    type Session* = ref object
      id*:    string
      count*: int
    
    var sessions: Table[string, Session]
    
    proc http_handler(req: Request): Future[void] {.async.} =
      let id = "1"
      if id notin sessions:
        sessions[id] = Session(id: id) # <= problem here, global var
      let session = sessions[id]
      await respond(req, Http200, "Ok")
    
    proc background_processing(_: AsyncFD): bool =
      for _, session in sessions:
        session.count += 1
    
    var server = new_async_http_server()
    async_check serve(server, Port(5000), http_handler, "localhost")
    add_timer(1000, false, background_processing)
    run_forever()
    
    
    Run

Reply via email to