# Pastebin pCXcYeEE import asyncdispatch, threadpool, random, math, logging, json, strutils import jester var idCounter: int proc newId(): int = idCounter += 1 result = idCounter let jesterPort* = 5000 proc doMath(): float = result = random(1000.0) for i in 1..100000: if result == 1.0: result = random(1000.0) result = sqrt(result) when isMainModule: settings: port = Port(jesterPort) routes: get "/sample": let requestId = $newId() info "[$1] Received request." % requestId let fv = spawn doMath() while true: if fv.isReady(): var flowResult = ^fv r = $(% flowResult) # If so, execute the handler body. info "[$1] Completed request." % requestId resp(r, contentType = "application/json") else: info "[$1] Waiting..." % requestId # Otherwise, yield in order to return control back to the main event loop. yield sleepAsync 10 runForever()