Repository navigation
Answer promises from thunked and dispatched untyped async methods #1534
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
eef68a7
60f2823
c9c19d8
48ab597
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| { | ||
| "order": [ | ||
| "<repo>/tests/corpus/6419-untyped-async-package/main.ts" | ||
| ], | ||
| "diags": [] | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| { | ||
| "order": [ | ||
| "<repo>/tests/corpus/6592-promise-armed-method-values/main.ts" | ||
| ], | ||
| "diags": [] | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| // Untyped async methods of a package, reached through the package's own | ||
| // untyped callers and prototype reflection, and overridden by a typed | ||
| // subclass. An async generator method called from the package answers its | ||
| // generator object. | ||
| import { Pool, Schema, limiter, listIssues, prototypeNames, validateAll } from "token-pool"; | ||
|
|
||
| class CountingPool extends Pool { | ||
| acquired = 0; | ||
| async acquire(): Promise<void> { | ||
| await super.acquire(); | ||
| this.acquired++; | ||
| } | ||
| } | ||
|
|
||
| async function main(): Promise<void> { | ||
| const pool = new CountingPool(1); | ||
| await pool.acquire(); | ||
| const waiting = pool.acquire(); | ||
| console.log("waiting", pool.nrWaiting()); | ||
| pool.release("t"); | ||
| await waiting; | ||
| console.log("acquired", pool.acquired, pool.nrWaiting()); | ||
| const base = new Pool(1); | ||
| console.log("token", await base.acquire()); | ||
| const run = limiter(1); | ||
| console.log(await Promise.all([run(async () => 1), run(async () => 2)])); | ||
| const schema = new Schema((value) => typeof value === "number"); | ||
| console.log(await validateAll(schema, [1, "x", 3])); | ||
| console.log(await listIssues(schema, ["p", 5, "q"])); | ||
| console.log(await schema.parseAsync(4)); | ||
| try { | ||
| await schema.parseAsync("y"); | ||
| } catch (e) { | ||
| console.log("rejected", e instanceof Error ? e.message : String(e)); | ||
| } | ||
| console.log(prototypeNames()); | ||
| } | ||
| main(); |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| // Parse steps that answer either a status record or a promise of one keep | ||
| // their method values: reads through untyped code, detached calls, and the | ||
| // per-instance rebinding of the base constructor all see the function. | ||
| import { map, number, object, record, set, stepDetached, stepKinds } from "status-schema"; | ||
| async function main(): Promise<void> { | ||
| const shaped = object({ count: number(), size: number() }); | ||
| const counts = record(number()); | ||
| const byName = map(number()); | ||
| const seen = set(number()); | ||
| console.log(stepKinds(shaped), "|", stepKinds(counts), "|", stepKinds(byName), "|", stepKinds(seen)); | ||
| console.log(shaped.safeParse({ count: 1, size: 2 }).success, shaped.safeParse({ count: "x", size: 2 }).success); | ||
| console.log(JSON.stringify(shaped.parse({ count: 3, size: 4 }))); | ||
| console.log(JSON.stringify(await shaped.parseAsync({ count: 5, size: 6 })), (await shaped.spa(7)).success); | ||
| console.log(counts.safeParse({ a: 1, b: 2 }).success, (await counts.safeParseAsync({ a: "x" })).success); | ||
| console.log(byName.safeParse(new Map([["a", 1]])).success, (await byName.safeParseAsync(new Map([["b", "x"]]))).success); | ||
| console.log(seen.safeParse(new Set([1, 2])).success, (await seen.spa(new Set([3]))).success); | ||
| console.log(await stepDetached(shaped, { count: 1, size: 1 }), "|", await stepDetached(counts, { a: "x" })); | ||
| console.log(await stepDetached(byName, new Map([["c", 2]])), "|", await stepDetached(seen, [1])); | ||
| try { | ||
| await counts.parseAsync(null); | ||
| } catch (e) { | ||
| console.log("rejected", e instanceof Error ? e.message : String(e)); | ||
| } | ||
| const nested = object({ inner: record(number()), tags: set(number()) }); | ||
| console.log(JSON.stringify(await nested.parseAsync({ inner: { q: 1 }, tags: new Set([1]) }))); | ||
| } | ||
| main(); |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Uh oh!
There was an error while loading. Please reload this page.