diff options
author | bptato <nincsnevem662@gmail.com> | 2024-09-30 21:25:20 +0200 |
---|---|---|
committer | bptato <nincsnevem662@gmail.com> | 2024-09-30 21:25:20 +0200 |
commit | f9433f13765ca6ec6aa5d2c34dd4d3c76d93c08a (patch) | |
tree | b94a661a8821aafe1cc6945ead210abc1349e3de /src/js | |
parent | bcadca71a694c68263d03da27fcaf3fc897da38f (diff) | |
download | chawan-f9433f13765ca6ec6aa5d2c34dd4d3c76d93c08a.tar.gz |
timeout: accept err stream as param
gets rid of a todo. (not sure why I thought this was important, but it sure looks nicer)
Diffstat (limited to 'src/js')
-rw-r--r-- | src/js/timeout.nim | 14 |
1 files changed, 6 insertions, 8 deletions
diff --git a/src/js/timeout.nim b/src/js/timeout.nim index 72a68dbc..6ff796f2 100644 --- a/src/js/timeout.nim +++ b/src/js/timeout.nim @@ -27,16 +27,14 @@ type timeoutid: int32 timeouts: seq[TimeoutEntry] jsctx: JSContext - err: DynStream #TODO shouldn't be needed evalJSFree: EvalJSFree opaque: RootRef sorted: bool -func newTimeoutState*(jsctx: JSContext; err: DynStream; - evalJSFree: EvalJSFree; opaque: RootRef): TimeoutState = +func newTimeoutState*(jsctx: JSContext; evalJSFree: EvalJSFree; + opaque: RootRef): TimeoutState = return TimeoutState( jsctx: jsctx, - err: err, evalJSFree: evalJSFree, opaque: opaque, sorted: true @@ -84,12 +82,12 @@ proc setTimeout*(state: var TimeoutState; t: TimeoutType; handler: JSValue; state.sorted = false return id -proc runEntry(state: var TimeoutState; entry: TimeoutEntry) = +proc runEntry(state: var TimeoutState; entry: TimeoutEntry; err: DynStream) = if JS_IsFunction(state.jsctx, entry.val): let ret = JS_Call(state.jsctx, entry.val, JS_UNDEFINED, cint(entry.args.len), entry.args.toJSValueArray()) if JS_IsException(ret): - state.jsctx.writeException(state.err) + state.jsctx.writeException(err) JS_FreeValue(state.jsctx, ret) else: var s: string @@ -107,7 +105,7 @@ proc sortAndGetTimeout*(state: var TimeoutState): cint = let now = getUnixMillis() return cint(max(state.timeouts[^1].expires - now, -1)) -proc run*(state: var TimeoutState): bool = +proc run*(state: var TimeoutState; err: DynStream): bool = let H = state.timeouts.high let now = getUnixMillis() var found = false @@ -115,7 +113,7 @@ proc run*(state: var TimeoutState): bool = if state.timeouts[i].expires > now: break let entry = state.timeouts[i] - state.runEntry(entry) + state.runEntry(entry, err) found = true case entry.t of ttTimeout: state.clearTimeout0(i) |