My understanding is that strings are sequences of bytes, allocated on the heap, 
and therefore are cleaned up by GC (?more frequently?).

You could also do a `deepCopy` :
    
    
    import prologue
    import nwt
    
    ## To just set up threadvar and initialize per thread.
    var
      globalTemplates = newNwt("templates/*.html")
      templates {.threadvar.} : Nwt
    
    let settings = newSettings(
      address="0.0.0.0",
      debug=false,
      port=Port(8000),
    )
    
    var app = newApp(
      settings=settings
    )
    
    proc initTemplates() =
      {.cast(gcsafe).}:
        if templates.isNil:
          deepCopy(templates, globalTemplates)
    
    proc index(ctx: Context) {.async, gcsafe.} =
      initTemplates()
      resp templates.renderTemplate("index.html")
    
    app.addRoute("/", index)
    
    app.run()
    
    
    Run

BUT... doing that requires another compiler flag => `--tlsEmulation:off`

Reply via email to