about summary refs log tree commit diff stats
path: root/src/io
diff options
context:
space:
mode:
authorbptato <nincsnevem662@gmail.com>2023-08-28 22:44:26 +0200
committerbptato <nincsnevem662@gmail.com>2023-08-28 22:44:26 +0200
commit9026c578f637fffee792b4397251f0ca4562caa5 (patch)
treeb25728bc374d6e2f8f6bb9a715ebfa02c286648e /src/io
parent1422f3393301cd6105b3939be194c7c119fcf967 (diff)
downloadchawan-9026c578f637fffee792b4397251f0ca4562caa5.tar.gz
refactor: Result[T, JSError] -> JSResult[T]
Diffstat (limited to 'src/io')
-rw-r--r--src/io/loader.nim6
-rw-r--r--src/io/response.nim9
2 files changed, 7 insertions, 8 deletions
diff --git a/src/io/loader.nim b/src/io/loader.nim
index f263e031..c497b1dd 100644
--- a/src/io/loader.nim
+++ b/src/io/loader.nim
@@ -89,7 +89,7 @@ type
     # loader proxy.
     acceptProxy*: bool
 
-  FetchPromise* = Promise[Result[Response, JSError]]
+  FetchPromise* = Promise[JSResult[Response]]
 
 proc addFd(ctx: LoaderContext, fd: int, flags: int) =
   ctx.extra_fds.add(curl_waitfd(
@@ -333,12 +333,12 @@ proc onConnected*(loader: FileLoader, fd: int) =
       bodyRead: response.bodyRead
     )
     SocketStream(stream).source.getFd().setBlocking(false)
-    promise.resolve(Result[Response, JSError].ok(response))
+    promise.resolve(JSResult[Response].ok(response))
   else:
     loader.unregisterFun(fd)
     loader.unregistered.add(fd)
     let err = newTypeError("NetworkError when attempting to fetch resource")
-    promise.resolve(Result[Response, JSError].err(err))
+    promise.resolve(JSResult[Response].err(err))
   loader.connecting.del(fd)
 
 proc onRead*(loader: FileLoader, fd: int) =
diff --git a/src/io/response.nim b/src/io/response.nim
index 75e3d664..6d4db42f 100644
--- a/src/io/response.nim
+++ b/src/io/response.nim
@@ -53,20 +53,19 @@ proc close*(response: Response) {.jsfunc.} =
 
 proc text*(response: Response): Promise[JSResult[string]] {.jsfunc.} =
   if response.bodyRead == nil:
-    let p = newPromise[Result[string, JSError]]()
-    let err = Result[string, JSError]
+    let p = newPromise[JSResult[string]]()
+    let err = JSResult[string]
       .err(newTypeError("Body has already been consumed"))
     p.resolve(err)
     return p
   let bodyRead = response.bodyRead
   response.bodyRead = nil
-  return bodyRead.then(proc(s: string): Result[string, JSError] =
+  return bodyRead.then(proc(s: string): JSResult[string] =
     ok(s))
 
 proc json(ctx: JSContext, this: Response): Promise[JSResult[JSValue]]
     {.jsfunc.} =
-  return this.text().then(proc(s: Result[string, JSError]):
-      Result[JSValue, JSError] =
+  return this.text().then(proc(s: JSResult[string]): JSResult[JSValue] =
     let s = ?s
     return ok(JS_ParseJSON(ctx, cstring(s), cast[csize_t](s.len),
       cstring"<input>")))