From cc5689eaf4f7cfa158e31107906434da9aed62bf Mon Sep 17 00:00:00 2001 From: lonkaars Date: Thu, 29 Jun 2023 23:25:01 +0200 Subject: WIP examples + change `.prepare()` to `await .ready` --- core/api.ts | 4 ++-- core/http/client.ts | 4 +--- core/http/server.ts | 1 - core/raw/api.ts | 14 +++++++------- 4 files changed, 10 insertions(+), 13 deletions(-) (limited to 'core') diff --git a/core/api.ts b/core/api.ts index 0891081..017e131 100644 --- a/core/api.ts +++ b/core/api.ts @@ -7,8 +7,8 @@ import { ParseResult } from "../language/types.ts"; * swapped easily. */ export default abstract class API { - /** @summary prepare API client */ - abstract prepare(): Promise; + /** @summary resolved when ready */ + abstract ready: Promise; /** @summary parse sentence */ abstract parseSentence(input: string): Promise; diff --git a/core/http/client.ts b/core/http/client.ts index a77b616..365aa76 100644 --- a/core/http/client.ts +++ b/core/http/client.ts @@ -1,6 +1,5 @@ import "../../util/array.ts"; -import { ParseResult } from "../../language/types.ts"; import API from "../api.ts"; import { ConnectionProps, ConnectionPropsDefault } from "./props.ts"; import { APIRequest, APIRequestParseSentence, APIResponseParseSentence } from "./types.ts"; @@ -13,13 +12,12 @@ import { APIRequest, APIRequestParseSentence, APIResponseParseSentence } from ". */ export default class YomikunRemoteAPIClient implements API { private props: ConnectionProps; + ready: Promise = Promise.resolve(); constructor(options?: ConnectionProps) { this.props = { ...ConnectionPropsDefault, ...options }; } - async prepare() { } - private async request(details: APIRequest) { var response = await fetch(`http://${this.props.host}:${this.props.port}`, { method: "POST", diff --git a/core/http/server.ts b/core/http/server.ts index b5d6c13..1af8d25 100644 --- a/core/http/server.ts +++ b/core/http/server.ts @@ -2,7 +2,6 @@ import { serve } from "https://deno.land/std@0.192.0/http/server.ts"; import "../../util/string.ts"; -import { ParseResult } from "../../language/types.ts"; import YomikunRAWAPI from "../raw/api.ts"; import { ConnectionProps, ConnectionPropsDefault } from "./props.ts"; import { APIRequest, APIRequestParseSentence, APIResponseParseSentence } from "./types.ts"; diff --git a/core/raw/api.ts b/core/raw/api.ts index 2d29eed..06db022 100644 --- a/core/raw/api.ts +++ b/core/raw/api.ts @@ -5,6 +5,7 @@ import YomikunError from "../../util/error.ts"; /** @summary internal Yomikun API client (DO NOT USE DIRECTLY) */ export default class YomikunRAWAPI implements API { private _parser: Parser; + ready: Promise; constructor() { if (this.constructor === YomikunRAWAPI) { @@ -12,16 +13,15 @@ export default class YomikunRAWAPI implements API { } this._parser = new Parser(); - } - async prepare() { - await Promise.all([ - this._parser.prepare(), - ]); - } + this.ready = new Promise(async resolve => { + await this._parser.ready; + resolve(); + }) + } async parseSentence(input: string) { - return this._parser.parse(input); + return await this._parser.parse(input); } }; -- cgit v1.2.3