From 0ad46e6f5c2b15fd5dafc7afe7e1531a2c7054e2 Mon Sep 17 00:00:00 2001 From: bkiac Date: Wed, 27 Nov 2024 14:18:21 +0100 Subject: [PATCH] Start async option docs --- src/async_option.ts | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/async_option.ts b/src/async_option.ts index def48c1..aeaae81 100644 --- a/src/async_option.ts +++ b/src/async_option.ts @@ -1,3 +1,8 @@ +/** + * This module contains the `AsyncOption` class, which is a promise that resolves to an `Option`. + * @module + */ + import { AsyncResult } from "./async_result.ts"; import { None, type Option, type OptionMatch, type OptionMatchAsync, Some } from "./option.ts"; @@ -7,8 +12,15 @@ import { None, type Option, type OptionMatch, type OptionMatchAsync, Some } from * This class is useful for chaining multiple asynchronous operations that return an `Option`. */ export class AsyncOption implements PromiseLike> { + /** + * The promise that resolves to an `Option`. + */ public readonly promise: Promise> | PromiseLike> | AsyncOption; + /** + * Creates a new `AsyncOption`. + * @param promise - The promise that resolves to an `Option`. + */ public constructor(promise: Promise> | PromiseLike> | AsyncOption) { this.promise = promise; } @@ -17,10 +29,16 @@ export class AsyncOption implements PromiseLike> { return "AsyncOption"; } + /** + * Converts the `AsyncOption` to a JSON object. + */ public toJSON(): { AsyncOption: Promise> | PromiseLike> | AsyncOption } { return { AsyncOption: this.promise }; } + /** + * Converts the `AsyncOption` to a string. + */ public toString(): string { return `AsyncOption(${this.promise.toString()})`; }