The first solution implies the instance is already available when using 
onSignal, which is not the case, since this is a library, which will be used by 
others. They will probably inherit this App (which I forgot to add of RootObj), 
so it must be run when the user creates the instance and start the app, not 
when they import this module.

The second solution seems like it would have problems if the user (the one who 
imports this library), does not understand that templates might have adverse 
effects, if used with functions that return an App, but also changes the app, 
like this:
    
    
    template start*(app: var App): bool =
      app.running = true
      app.anotherVar = 1
      ... onSignal, etc.
    
    proc init*(app: App): var App =
      app.ii += 2
    
    var myapp = App()
    myapp.init.start
    
    
    Run

>From my understanding, app.ii would be 4, since it will run myapp.init 2 times 
>from the template (one on line app.running = true, and another from 
>app.anotherVar = 1, which it replaces with app.init.anotherVar = 1, correct? 
>I'm reluctant to expose this to the users, since it requires under the hood 
>knowledge of how it is implemented, as opposed to just know it is implemented.

Reply via email to