jpsider / RestPS

Simple ReST Framework for Powershell
MIT License
113 stars 30 forks source link

Asynchronous request handling #77

Open ShaunMaher opened 1 year ago

ShaunMaher commented 1 year ago

Hello.

Would it be possible to make RestPS handle requests asynchronously?

Imagine I have a dummy endpoint script that just does the following:

Start-Sleep -Seconds 30
Return "Wake Up"

If this endpoint is triggered, the /endpoint/status endpoint (and all other endpoints) also stop responding until the 30 second sleep is complete.

I'm no powershell expert like you kind folks but I did a little reading.

There is a "HttpListener.GetContextAsync" method but that just let's do do other things until the request context is ready. Apply timeouts, etc. It doesn't run the response generation logic Async.

Maybe, once you have a Context (Start-RestPSListener.ps1:80) you could pass off to a Job that does everything from Start-RestPSListener.ps1:85 to 163 so the loop that starts on Start-RestPSListener.ps1:75 could immediately get ready to "Invoke-GetContext" the next incoming (parallel) request. I dunno. I'm just guessing.

Cheers. Shaun.

jpsider commented 1 year ago

This is a duplicate of #64.