Skip to content

Commit

Permalink
debug
Browse files Browse the repository at this point in the history
  • Loading branch information
hazae41 committed May 22, 2023
1 parent e68e727 commit 7af530c
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 1 deletion.
3 changes: 3 additions & 0 deletions src/mods/debug/debug.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export namespace Debug {
export let debug = false
}
2 changes: 1 addition & 1 deletion src/mods/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
export * from "./debug/debug.js";
export * from "./result/index.js";

6 changes: 6 additions & 0 deletions src/mods/result/err.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { None, Some } from "@hazae41/option"
import { Promiseable } from "libs/promises/promises.js"
import { Class } from "libs/reflection/reflection.js"
import { Debug } from "mods/debug/debug.js"

export type ErrInner<E> = E extends Err<infer T> ? T : never

Expand All @@ -15,6 +16,8 @@ export class Err<T = unknown> {
constructor(
readonly inner: T
) {
if (!Debug.debug) return

const { stack } = new Error()

this.#timeout = setTimeout(() => {
Expand Down Expand Up @@ -71,6 +74,9 @@ export class Err<T = unknown> {
* Set this result as handled
*/
ignore(): this {
if (!this.#timeout)
return this

clearTimeout(this.#timeout)
this.#timeout = undefined

Expand Down
6 changes: 6 additions & 0 deletions src/mods/result/ok.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { None, Some } from "@hazae41/option"
import { Promiseable } from "libs/promises/promises.js"
import { Debug } from "mods/debug/debug.js"

export type OkInner<O> = O extends Ok<infer T> ? T : never

Expand All @@ -14,6 +15,8 @@ export class Ok<T = unknown> {
constructor(
readonly inner: T
) {
if (!Debug.debug) return

const { stack } = new Error()

this.#timeout = setTimeout(() => {
Expand Down Expand Up @@ -42,6 +45,9 @@ export class Ok<T = unknown> {
* Set this result as handled
*/
ignore(): this {
if (!this.#timeout)
return this

clearTimeout(this.#timeout)
this.#timeout = undefined

Expand Down

0 comments on commit 7af530c

Please sign in to comment.