diff --git a/http/server.ts b/http/server.ts index 30e3146ce0c8..5bbc7fd08174 100644 --- a/http/server.ts +++ b/http/server.ts @@ -8,7 +8,7 @@ import { BufReader, BufState, BufWriter } from "../io/bufio.ts"; import { TextProtoReader } from "../textproto/mod.ts"; import { STATUS_TEXT } from "./http_status.ts"; import { assert } from "../testing/asserts.ts"; -import { Latch, deferred, Deferred } from "../util/async.ts"; +import { Channel, deferred, Deferred } from "../util/async.ts"; interface HttpConn extends Conn { // When read by a newly created request B, lastId is the id pointing to a previous @@ -292,7 +292,7 @@ async function readRequest( export class Server implements AsyncIterableIterator { private closing = false; private looping = false; - private latch = new Latch(); + private channel = new Channel(); constructor(public listener: Listener) {} @@ -326,12 +326,12 @@ export class Server implements AsyncIterableIterator { break; } - await this.latch.send(req); + await this.channel.send(req); } } async next(): Promise> { - const req = await this.latch.recv(); + const req = await this.channel.recv(); return { done: false, value: req }; } diff --git a/prettier/testdata/opts/0.ts b/prettier/testdata/opts/0.ts index fb85014a5e9e..0277269118cf 100644 --- a/prettier/testdata/opts/0.ts +++ b/prettier/testdata/opts/0.ts @@ -1,2 +1,2 @@ -console.log(0) -console.log([function foo() {}, function baz() {}, a => {}]) +console.log(0); +console.log([function foo() {}, function baz() {}, (a) => {}]); diff --git a/prettier/testdata/opts/1.ts b/prettier/testdata/opts/1.ts index c23a66c28e91..4748527e94fa 100644 --- a/prettier/testdata/opts/1.ts +++ b/prettier/testdata/opts/1.ts @@ -1 +1 @@ -console.log ("1") +console.log('1'); diff --git a/prettier/testdata/opts/2.ts b/prettier/testdata/opts/2.ts index 2cfe9aece463..e0c70341fd62 100644 --- a/prettier/testdata/opts/2.ts +++ b/prettier/testdata/opts/2.ts @@ -1 +1 @@ -console.log({a:1}) +console.log({a: 1}); diff --git a/util/async.ts b/util/async.ts index e2bd8c958d43..c664c9ce28b3 100644 --- a/util/async.ts +++ b/util/async.ts @@ -28,12 +28,10 @@ export function deferred(): Deferred { return Object.assign(promise, methods) as Deferred; } -export class Latch { - // TODO(ry) Can this be done without using Arrays? - - // Array of `[resolve_function, value]` tuples. +/** Sends objects between asynchronous tasks, with backpressure. */ +export class Channel { + // TODO(ry) Can Channel be implemented without using Arrays? private sendQueue: Array<[() => void, T]> = []; - // Array of `resolve_function` values. private recvQueue: Array<(value: T) => void> = []; send(value: T): Promise { diff --git a/util/async_test.ts b/util/async_test.ts index 2da72075b0c9..226cb784dc92 100644 --- a/util/async_test.ts +++ b/util/async_test.ts @@ -1,27 +1,27 @@ // Copyright 2018-2019 the Deno authors. All rights reserved. MIT license. import { test, runIfMain } from "../testing/mod.ts"; import { assertEquals } from "../testing/asserts.ts"; -import { Latch, deferred } from "./async.ts"; +import { Channel, deferred } from "./async.ts"; test(async function asyncDeferred(): Promise { const d = deferred(); d.resolve(12); }); -async function send3(latch: Latch): Promise { - await latch.send(1); - await latch.send(2); - await latch.send(3); +async function send3(channel: Channel): Promise { + await channel.send(1); + await channel.send(2); + await channel.send(3); } -test(async function asyncLatch(): Promise { - const latch = new Latch(); - send3(latch); +test(async function asyncChannel(): Promise { + const channel = new Channel(); + send3(channel); - assertEquals(1, await latch.recv()); - assertEquals(2, await latch.recv()); - assertEquals(3, await latch.recv()); - let _lastPromise = latch.recv(); + assertEquals(1, await channel.recv()); + assertEquals(2, await channel.recv()); + assertEquals(3, await channel.recv()); + let _lastPromise = channel.recv(); }); runIfMain(import.meta);