I'd like for this program to be able to do two things: check for console input 
asynchronously and load a dynamically linked library (some time after the 
console input checking begun). So here's what I tried:
    
    
    import threadpool, dynlib
    
    
    var
        input: FlowVar[TaintedString]
        command: string
    
    proc asyncConsoleInput =
        if input == nil:
            input = spawn readLine(stdin)
        
        elif input.isReady:
            command = ^input
            input = spawn readLine(stdin)
    
    
    var
        running = true
        lib: LibHandle
    
    while running:
        
        # Console input
        asyncConsoleInput()
        if command != nil:
            if command == "quit": running = false
            command = nil
        
        # Loading a DLL
        if lib == nil:
            echo "loading lib..."
            lib = loadLib("test.dll")
            echo "lib loaded!"
    

Both the asynchronous input checking and the loading of the lib work fine on 
their own, but in combination I encounter an issue where readLine suddenly 
blocks the main thread the moment loadLib is called. Any idea?

Reply via email to