diff --git a/.eslintrc.json b/.eslintrc.json index 7c9588412969f..43a0b8caef01a 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -22,7 +22,8 @@ ], "@typescript-eslint/ban-ts-ignore": ["off"], "@typescript-eslint/no-empty-function": ["off"], - "no-return-await": "error" + "no-return-await": "error", + "require-await": "error" }, "overrides": [ { diff --git a/cli/js/buffer.ts b/cli/js/buffer.ts index 91c06a202cbc7..db2bb22e4d073 100644 --- a/cli/js/buffer.ts +++ b/cli/js/buffer.ts @@ -106,7 +106,7 @@ export class Buffer implements Reader, SyncReader, Writer, SyncWriter { return nread; } - async read(p: Uint8Array): Promise { + read(p: Uint8Array): Promise { const rr = this.readSync(p); return Promise.resolve(rr); } @@ -116,7 +116,7 @@ export class Buffer implements Reader, SyncReader, Writer, SyncWriter { return copyBytes(this.buf, p, m); } - async write(p: Uint8Array): Promise { + write(p: Uint8Array): Promise { const n = this.writeSync(p); return Promise.resolve(n); } diff --git a/cli/js/compiler.ts b/cli/js/compiler.ts index 914a0baf08a77..419f07063aade 100644 --- a/cli/js/compiler.ts +++ b/cli/js/compiler.ts @@ -302,7 +302,7 @@ async function runtimeCompile( } } -async function runtimeTranspile( +function runtimeTranspile( request: CompilerRequestRuntimeTranspile ): Promise> { const result: Record = {}; @@ -325,7 +325,7 @@ async function runtimeTranspile( ); result[fileName] = { source, map }; } - return result; + return Promise.resolve(result); } async function tsCompilerOnMessage({ diff --git a/cli/js/ops/fetch.ts b/cli/js/ops/fetch.ts index 8d6a461ab3d7e..09b9ac1eca3e0 100644 --- a/cli/js/ops/fetch.ts +++ b/cli/js/ops/fetch.ts @@ -15,7 +15,7 @@ export interface FetchResponse { headers: Array<[string, string]>; } -export async function fetch( +export function fetch( args: FetchRequest, body: ArrayBufferView | undefined ): Promise { diff --git a/cli/js/ops/fs/make_temp.ts b/cli/js/ops/fs/make_temp.ts index aeab9afc7acf0..85dea5f20998c 100644 --- a/cli/js/ops/fs/make_temp.ts +++ b/cli/js/ops/fs/make_temp.ts @@ -11,9 +11,7 @@ export function makeTempDirSync(options: MakeTempOptions = {}): string { return sendSync("op_make_temp_dir", options); } -export async function makeTempDir( - options: MakeTempOptions = {} -): Promise { +export function makeTempDir(options: MakeTempOptions = {}): Promise { return sendAsync("op_make_temp_dir", options); } @@ -21,8 +19,6 @@ export function makeTempFileSync(options: MakeTempOptions = {}): string { return sendSync("op_make_temp_file", options); } -export async function makeTempFile( - options: MakeTempOptions = {} -): Promise { +export function makeTempFile(options: MakeTempOptions = {}): Promise { return sendAsync("op_make_temp_file", options); } diff --git a/cli/js/ops/fs/open.ts b/cli/js/ops/fs/open.ts index 2ac5c715cded2..87696935f32e9 100644 --- a/cli/js/ops/fs/open.ts +++ b/cli/js/ops/fs/open.ts @@ -26,7 +26,7 @@ export function openSync( return sendSync("op_open", { path, options, openMode, mode }); } -export async function open( +export function open( path: string, openMode: OpenMode | undefined, options: OpenOptions | undefined diff --git a/cli/js/ops/fs/read_link.ts b/cli/js/ops/fs/read_link.ts index 403cd6def2517..4ac8db3dbab82 100644 --- a/cli/js/ops/fs/read_link.ts +++ b/cli/js/ops/fs/read_link.ts @@ -5,6 +5,6 @@ export function readlinkSync(path: string): string { return sendSync("op_read_link", { path }); } -export async function readlink(path: string): Promise { +export function readlink(path: string): Promise { return sendAsync("op_read_link", { path }); } diff --git a/cli/js/ops/fs/realpath.ts b/cli/js/ops/fs/realpath.ts index e68e32bf020e5..e8a904079873a 100644 --- a/cli/js/ops/fs/realpath.ts +++ b/cli/js/ops/fs/realpath.ts @@ -5,6 +5,6 @@ export function realpathSync(path: string): string { return sendSync("op_realpath", { path }); } -export async function realpath(path: string): Promise { +export function realpath(path: string): Promise { return sendAsync("op_realpath", { path }); } diff --git a/cli/js/ops/fs/seek.ts b/cli/js/ops/fs/seek.ts index dfac9bf636bd6..c7e4c9172fc3c 100644 --- a/cli/js/ops/fs/seek.ts +++ b/cli/js/ops/fs/seek.ts @@ -10,7 +10,7 @@ export function seekSync( return sendSync("op_seek", { rid, offset, whence }); } -export async function seek( +export function seek( rid: number, offset: number, whence: SeekMode diff --git a/cli/js/ops/fs_events.ts b/cli/js/ops/fs_events.ts index 706efc1b0d82f..4c08995b85636 100644 --- a/cli/js/ops/fs_events.ts +++ b/cli/js/ops/fs_events.ts @@ -15,15 +15,15 @@ class FsEvents implements AsyncIterableIterator { this.rid = sendSync("op_fs_events_open", { recursive, paths }); } - async next(): Promise> { + next(): Promise> { return sendAsync("op_fs_events_poll", { rid: this.rid }); } - async return(value?: FsEvent): Promise> { + return(value?: FsEvent): Promise> { close(this.rid); - return { value, done: true }; + return Promise.resolve({ value, done: true }); } [Symbol.asyncIterator](): AsyncIterableIterator { diff --git a/cli/js/ops/net.ts b/cli/js/ops/net.ts index 5a72be8c6e7de..25f3a83229601 100644 --- a/cli/js/ops/net.ts +++ b/cli/js/ops/net.ts @@ -31,7 +31,7 @@ interface AcceptResponse { }; } -export async function accept(rid: number): Promise { +export function accept(rid: number): Promise { return sendAsync("op_accept", { rid }); } @@ -74,7 +74,7 @@ export interface ConnectRequest { port: number; } -export async function connect(args: ConnectRequest): Promise { +export function connect(args: ConnectRequest): Promise { return sendAsync("op_connect", args); } @@ -87,7 +87,7 @@ interface ReceiveResponse { }; } -export async function receive( +export function receive( rid: number, zeroCopy: Uint8Array ): Promise { diff --git a/cli/js/ops/process.ts b/cli/js/ops/process.ts index 845909d5dda1a..384718cefa418 100644 --- a/cli/js/ops/process.ts +++ b/cli/js/ops/process.ts @@ -12,7 +12,7 @@ interface RunStatusResponse { exitSignal: number; } -export async function runStatus(rid: number): Promise { +export function runStatus(rid: number): Promise { return sendAsync("op_run_status", { rid }); } diff --git a/cli/js/ops/repl.ts b/cli/js/ops/repl.ts index 3f40f44561155..1781aa08931ad 100644 --- a/cli/js/ops/repl.ts +++ b/cli/js/ops/repl.ts @@ -6,6 +6,6 @@ export function startRepl(historyFile: string): number { return sendSync("op_repl_start", { historyFile }); } -export async function readline(rid: number, prompt: string): Promise { +export function readline(rid: number, prompt: string): Promise { return sendAsync("op_repl_readline", { rid, prompt }); } diff --git a/cli/js/ops/runtime_compiler.ts b/cli/js/ops/runtime_compiler.ts index 035a4ef59a291..b46670acef093 100644 --- a/cli/js/ops/runtime_compiler.ts +++ b/cli/js/ops/runtime_compiler.ts @@ -9,7 +9,7 @@ interface CompileRequest { bundle: boolean; } -export async function compile(request: CompileRequest): Promise { +export function compile(request: CompileRequest): Promise { return sendAsync("op_compile", request); } @@ -18,6 +18,6 @@ interface TranspileRequest { options?: string; } -export async function transpile(request: TranspileRequest): Promise { +export function transpile(request: TranspileRequest): Promise { return sendAsync("op_transpile", request); } diff --git a/cli/js/ops/signal.ts b/cli/js/ops/signal.ts index 3c8d021a03fa5..09c1781054223 100644 --- a/cli/js/ops/signal.ts +++ b/cli/js/ops/signal.ts @@ -5,7 +5,7 @@ export function bindSignal(signo: number): { rid: number } { return sendSync("op_signal_bind", { signo }); } -export async function pollSignal(rid: number): Promise<{ done: boolean }> { +export function pollSignal(rid: number): Promise<{ done: boolean }> { return sendAsync("op_signal_poll", { rid }); } diff --git a/cli/js/ops/tls.ts b/cli/js/ops/tls.ts index b52ad65bbe141..e52143cb073a0 100644 --- a/cli/js/ops/tls.ts +++ b/cli/js/ops/tls.ts @@ -23,7 +23,7 @@ interface ConnectTLSResponse { }; } -export async function connectTLS( +export function connectTLS( args: ConnectTLSRequest ): Promise { return sendAsync("op_connect_tls", args); @@ -43,7 +43,7 @@ interface AcceptTLSResponse { }; } -export async function acceptTLS(rid: number): Promise { +export function acceptTLS(rid: number): Promise { return sendAsync("op_accept_tls", { rid }); } diff --git a/cli/js/ops/worker_host.ts b/cli/js/ops/worker_host.ts index 1a7e671f4e83c..0b9f81795a9b3 100644 --- a/cli/js/ops/worker_host.ts +++ b/cli/js/ops/worker_host.ts @@ -24,6 +24,6 @@ export function hostPostMessage(id: number, data: Uint8Array): void { sendSync("op_host_post_message", { id }, data); } -export async function hostGetMessage(id: number): Promise { +export function hostGetMessage(id: number): Promise { return sendAsync("op_host_get_message", { id }); } diff --git a/cli/js/permissions.ts b/cli/js/permissions.ts index 097c5048aabe2..8c2025319fdde 100644 --- a/cli/js/permissions.ts +++ b/cli/js/permissions.ts @@ -47,19 +47,19 @@ export class PermissionStatus { } export class Permissions { - async query(desc: PermissionDescriptor): Promise { + query(desc: PermissionDescriptor): Promise { const state = permissionsOps.query(desc); - return new PermissionStatus(state); + return Promise.resolve(new PermissionStatus(state)); } - async revoke(desc: PermissionDescriptor): Promise { + revoke(desc: PermissionDescriptor): Promise { const state = permissionsOps.revoke(desc); - return new PermissionStatus(state); + return Promise.resolve(new PermissionStatus(state)); } - async request(desc: PermissionDescriptor): Promise { + request(desc: PermissionDescriptor): Promise { const state = permissionsOps.request(desc); - return new PermissionStatus(state); + return Promise.resolve(new PermissionStatus(state)); } } diff --git a/cli/js/process.ts b/cli/js/process.ts index 991133047d3d9..ded1458a2155f 100644 --- a/cli/js/process.ts +++ b/cli/js/process.ts @@ -55,7 +55,7 @@ export class Process { } } - async status(): Promise { + status(): Promise { return runStatus(this.rid); } diff --git a/cli/js/testing.ts b/cli/js/testing.ts index 08bb2db8719bc..22e719719fb94 100644 --- a/cli/js/testing.ts +++ b/cli/js/testing.ts @@ -289,7 +289,7 @@ export class ConsoleTestReporter implements TestReporter { this.encoder = new TextEncoder(); } - private log(msg: string, noNewLine = false): void { + private log(msg: string, noNewLine = false): Promise { if (!noNewLine) { msg += "\n"; } @@ -298,19 +298,22 @@ export class ConsoleTestReporter implements TestReporter { // compared to `console.log`; `core.print` on the other hand // is line-buffered and doesn't output message without newline stdout.writeSync(this.encoder.encode(msg)); + return Promise.resolve(); } - async start(event: TestEventStart): Promise { + start(event: TestEventStart): Promise { this.log(`running ${event.tests} tests`); + return Promise.resolve(); } - async testStart(event: TestEventTestStart): Promise { + testStart(event: TestEventTestStart): Promise { const { name } = event; this.log(`test ${name} ... `, true); + return Promise.resolve(); } - async testEnd(event: TestEventTestEnd): Promise { + testEnd(event: TestEventTestEnd): Promise { const { result } = event; switch (result.status) { @@ -324,9 +327,11 @@ export class ConsoleTestReporter implements TestReporter { this.log(`${YELLOW_IGNORED} ${formatDuration(result.duration)}`); break; } + + return Promise.resolve(); } - async end(event: TestEventEnd): Promise { + end(event: TestEventEnd): Promise { const { stats, duration, results } = event; // Attempting to match the output of Rust's test runner. const failedTests = results.filter(r => r.error); @@ -354,6 +359,8 @@ export class ConsoleTestReporter implements TestReporter { `${stats.filtered} filtered out ` + `${formatDuration(duration)}\n` ); + + return Promise.resolve(); } } diff --git a/cli/js/tests/dispatch_json_test.ts b/cli/js/tests/dispatch_json_test.ts index a2306dda8ced9..4e95b86a2858f 100644 --- a/cli/js/tests/dispatch_json_test.ts +++ b/cli/js/tests/dispatch_json_test.ts @@ -19,7 +19,7 @@ unitTest( } ); -unitTest(async function malformedJsonControlBuffer(): Promise { +unitTest(function malformedJsonControlBuffer(): void { // @ts-ignore const opId = Deno.core.ops()["op_open"]; // @ts-ignore diff --git a/cli/js/tests/dispatch_minimal_test.ts b/cli/js/tests/dispatch_minimal_test.ts index 724a4169815ed..60bb620db6966 100644 --- a/cli/js/tests/dispatch_minimal_test.ts +++ b/cli/js/tests/dispatch_minimal_test.ts @@ -25,7 +25,7 @@ unitTest(async function sendAsyncStackTrace(): Promise { } }); -unitTest(async function malformedMinimalControlBuffer(): Promise { +unitTest(function malformedMinimalControlBuffer(): void { // @ts-ignore const readOpId = Deno.core.ops()["op_read"]; // @ts-ignore diff --git a/cli/js/tests/event_target_test.ts b/cli/js/tests/event_target_test.ts index 09d47f7048c9c..020db1acd3ea8 100644 --- a/cli/js/tests/event_target_test.ts +++ b/cli/js/tests/event_target_test.ts @@ -185,7 +185,7 @@ unitTest(function eventTargetShouldAcceptAsyncFunction(): void { const event = new Event("foo", { bubbles: true, cancelable: false }); let callCount = 0; - const listener = async (e: Event): Promise => { + const listener = (e: Event): void => { assertEquals(e, event); ++callCount; }; @@ -210,7 +210,7 @@ unitTest( let callCount = 0; const listener = { - async handleEvent(e: Event): Promise { + handleEvent(e: Event): void { assertEquals(e, event); ++callCount; } diff --git a/cli/js/tests/files_test.ts b/cli/js/tests/files_test.ts index b087d7398daf0..39af460b8850d 100644 --- a/cli/js/tests/files_test.ts +++ b/cli/js/tests/files_test.ts @@ -51,16 +51,16 @@ unitTest(async function readerToAsyncIterator(): Promise { constructor(private readonly s: string) {} - async read(p: Uint8Array): Promise { + read(p: Uint8Array): Promise { const n = Math.min(p.byteLength, this.buf.byteLength - this.offset); p.set(this.buf.slice(this.offset, this.offset + n)); this.offset += n; if (n === 0) { - return Deno.EOF; + return Promise.resolve(Deno.EOF); } - return n; + return Promise.resolve(n); } } diff --git a/cli/js/tests/process_test.ts b/cli/js/tests/process_test.ts index 77c3065eb4adc..e2da6cab59c3f 100644 --- a/cli/js/tests/process_test.ts +++ b/cli/js/tests/process_test.ts @@ -359,9 +359,7 @@ if (Deno.build.os !== "win") { p.close(); }); - unitTest({ perms: { run: true } }, async function killFailed(): Promise< - void - > { + unitTest({ perms: { run: true } }, function killFailed(): void { const p = run({ args: ["python", "-c", "from time import sleep; sleep(10000)"] }); diff --git a/cli/js/tests/read_link_test.ts b/cli/js/tests/read_link_test.ts index 409f3711018e0..156b31070d860 100644 --- a/cli/js/tests/read_link_test.ts +++ b/cli/js/tests/read_link_test.ts @@ -18,9 +18,7 @@ unitTest( } ); -unitTest({ perms: { read: false } }, async function readlinkSyncPerm(): Promise< - void -> { +unitTest({ perms: { read: false } }, function readlinkSyncPerm(): void { let caughtError = false; try { Deno.readlinkSync("/symlink"); diff --git a/cli/js/tests/signal_test.ts b/cli/js/tests/signal_test.ts index e4339e2908879..c966e696b9ed6 100644 --- a/cli/js/tests/signal_test.ts +++ b/cli/js/tests/signal_test.ts @@ -15,7 +15,7 @@ function defer(n: number): Promise { unitTest( { ignore: Deno.build.os !== "win" }, - async function signalsNotImplemented(): Promise { + function signalsNotImplemented(): void { assertThrows( () => { Deno.signal(1); @@ -162,7 +162,7 @@ unitTest( unitTest( { ignore: Deno.build.os === "win", perms: { run: true } }, - async function signalShorthandsTest(): Promise { + function signalShorthandsTest(): void { let s: Deno.SignalStream; s = Deno.signals.alarm(); // for SIGALRM assert(s instanceof Deno.SignalStream); diff --git a/cli/js/tests/stat_test.ts b/cli/js/tests/stat_test.ts index e51204b6e157a..78582900ee13f 100644 --- a/cli/js/tests/stat_test.ts +++ b/cli/js/tests/stat_test.ts @@ -3,9 +3,7 @@ import { unitTest, assert, assertEquals } from "./test_util.ts"; // TODO Add tests for modified, accessed, and created fields once there is a way // to create temp files. -unitTest({ perms: { read: true } }, async function statSyncSuccess(): Promise< - void -> { +unitTest({ perms: { read: true } }, function statSyncSuccess(): void { const packageInfo = Deno.statSync("README.md"); assert(packageInfo.isFile()); assert(!packageInfo.isSymlink()); @@ -19,9 +17,7 @@ unitTest({ perms: { read: true } }, async function statSyncSuccess(): Promise< assert(!testsInfo.isSymlink()); }); -unitTest({ perms: { read: false } }, async function statSyncPerm(): Promise< - void -> { +unitTest({ perms: { read: false } }, function statSyncPerm(): void { let caughtError = false; try { Deno.statSync("README.md"); @@ -32,9 +28,7 @@ unitTest({ perms: { read: false } }, async function statSyncPerm(): Promise< assert(caughtError); }); -unitTest({ perms: { read: true } }, async function statSyncNotFound(): Promise< - void -> { +unitTest({ perms: { read: true } }, function statSyncNotFound(): void { let caughtError = false; let badInfo; @@ -49,9 +43,7 @@ unitTest({ perms: { read: true } }, async function statSyncNotFound(): Promise< assertEquals(badInfo, undefined); }); -unitTest({ perms: { read: true } }, async function lstatSyncSuccess(): Promise< - void -> { +unitTest({ perms: { read: true } }, function lstatSyncSuccess(): void { const packageInfo = Deno.lstatSync("README.md"); assert(packageInfo.isFile()); assert(!packageInfo.isSymlink()); @@ -65,9 +57,7 @@ unitTest({ perms: { read: true } }, async function lstatSyncSuccess(): Promise< assert(!coreInfo.isSymlink()); }); -unitTest({ perms: { read: false } }, async function lstatSyncPerm(): Promise< - void -> { +unitTest({ perms: { read: false } }, function lstatSyncPerm(): void { let caughtError = false; try { Deno.lstatSync("README.md"); @@ -78,9 +68,7 @@ unitTest({ perms: { read: false } }, async function lstatSyncPerm(): Promise< assert(caughtError); }); -unitTest({ perms: { read: true } }, async function lstatSyncNotFound(): Promise< - void -> { +unitTest({ perms: { read: true } }, function lstatSyncNotFound(): void { let caughtError = false; let badInfo; @@ -185,7 +173,7 @@ unitTest({ perms: { read: true } }, async function lstatNotFound(): Promise< unitTest( { ignore: Deno.build.os !== "win", perms: { read: true, write: true } }, - async function statNoUnixFields(): Promise { + function statNoUnixFields(): void { const enc = new TextEncoder(); const data = enc.encode("Hello"); const tempDir = Deno.makeTempDirSync(); @@ -206,7 +194,7 @@ unitTest( unitTest( { ignore: Deno.build.os === "win", perms: { read: true, write: true } }, - async function statUnixFields(): Promise { + function statUnixFields(): void { const enc = new TextEncoder(); const data = enc.encode("Hello"); const tempDir = Deno.makeTempDirSync(); diff --git a/cli/js/tests/test_util.ts b/cli/js/tests/test_util.ts index 42301cf726e9e..980d32bac403b 100644 --- a/cli/js/tests/test_util.ts +++ b/cli/js/tests/test_util.ts @@ -328,7 +328,7 @@ unitTest(function permissionsMatches(): void { */ unitTest( { perms: { read: true } }, - async function assertAllUnitTestFilesImported(): Promise { + function assertAllUnitTestFilesImported(): void { const directoryTestFiles = Deno.readdirSync("./cli/js/tests/") .map(k => k.name) .filter( diff --git a/cli/js/tests/timers_test.ts b/cli/js/tests/timers_test.ts index 077e27ae68682..b7da6a8471c83 100644 --- a/cli/js/tests/timers_test.ts +++ b/cli/js/tests/timers_test.ts @@ -27,7 +27,7 @@ function deferred(): { }; } -async function waitForMs(ms: number): Promise { +function waitForMs(ms: number): Promise { return new Promise((resolve: () => void): number => setTimeout(resolve, ms)); } @@ -158,7 +158,7 @@ unitTest(async function intervalOrdering(): Promise { assertEquals(timeouts, 1); }); -unitTest(async function intervalCancelInvalidSilentFail(): Promise { +unitTest(function intervalCancelInvalidSilentFail(): void { // Should silently fail (no panic) clearInterval(2147483647); }); @@ -234,7 +234,7 @@ unitTest(async function timeoutBindThis(): Promise { } }); -unitTest(async function clearTimeoutShouldConvertToNumber(): Promise { +unitTest(function clearTimeoutShouldConvertToNumber(): void { let called = false; const obj = { valueOf(): number { diff --git a/cli/js/tests/tls_test.ts b/cli/js/tests/tls_test.ts index b405a94dd97e9..20dd62f9b1ef9 100644 --- a/cli/js/tests/tls_test.ts +++ b/cli/js/tests/tls_test.ts @@ -39,7 +39,7 @@ unitTest(async function connectTLSCertFileNoReadPerm(): Promise { unitTest( { perms: { read: true, net: true } }, - async function listenTLSNonExistentCertKeyFiles(): Promise { + function listenTLSNonExistentCertKeyFiles(): void { let err; const options = { hostname: "localhost", @@ -70,30 +70,27 @@ unitTest( } ); -unitTest( - { perms: { net: true } }, - async function listenTLSNoReadPerm(): Promise { - let err; - try { - Deno.listenTLS({ - hostname: "localhost", - port: 4500, - certFile: "cli/tests/tls/localhost.crt", - keyFile: "cli/tests/tls/localhost.key" - }); - } catch (e) { - err = e; - } - assert(err instanceof Deno.errors.PermissionDenied); - assertEquals(err.name, "PermissionDenied"); +unitTest({ perms: { net: true } }, function listenTLSNoReadPerm(): void { + let err; + try { + Deno.listenTLS({ + hostname: "localhost", + port: 4500, + certFile: "cli/tests/tls/localhost.crt", + keyFile: "cli/tests/tls/localhost.key" + }); + } catch (e) { + err = e; } -); + assert(err instanceof Deno.errors.PermissionDenied); + assertEquals(err.name, "PermissionDenied"); +}); unitTest( { perms: { read: true, write: true, net: true } }, - async function listenTLSEmptyKeyFile(): Promise { + function listenTLSEmptyKeyFile(): void { let err; const options = { hostname: "localhost", @@ -122,7 +119,7 @@ unitTest( unitTest( { perms: { read: true, write: true, net: true } }, - async function listenTLSEmptyCertFile(): Promise { + function listenTLSEmptyCertFile(): void { let err; const options = { hostname: "localhost", diff --git a/cli/js/web/body.ts b/cli/js/web/body.ts index ed21fa0ecfc1b..03c35848a74b3 100644 --- a/cli/js/web/body.ts +++ b/cli/js/web/body.ts @@ -306,7 +306,7 @@ export class Body implements domTypes.Body { return JSON.parse(raw); } - public async arrayBuffer(): Promise { + public arrayBuffer(): Promise { if ( this._bodySource instanceof Int8Array || this._bodySource instanceof Int16Array || @@ -318,20 +318,24 @@ export class Body implements domTypes.Body { this._bodySource instanceof Float32Array || this._bodySource instanceof Float64Array ) { - return this._bodySource.buffer as ArrayBuffer; + return Promise.resolve(this._bodySource.buffer as ArrayBuffer); } else if (this._bodySource instanceof ArrayBuffer) { - return this._bodySource; + return Promise.resolve(this._bodySource); } else if (typeof this._bodySource === "string") { const enc = new TextEncoder(); - return enc.encode(this._bodySource).buffer as ArrayBuffer; + return Promise.resolve( + enc.encode(this._bodySource).buffer as ArrayBuffer + ); } else if (this._bodySource instanceof ReadableStream) { // @ts-ignore return bufferFromStream(this._bodySource.getReader()); } else if (this._bodySource instanceof FormData) { const enc = new TextEncoder(); - return enc.encode(this._bodySource.toString()).buffer as ArrayBuffer; + return Promise.resolve( + enc.encode(this._bodySource.toString()).buffer as ArrayBuffer + ); } else if (!this._bodySource) { - return new ArrayBuffer(0); + return Promise.resolve(new ArrayBuffer(0)); } throw new Error( `Body type not yet implemented: ${this._bodySource.constructor.name}` diff --git a/cli/js/web/fetch.ts b/cli/js/web/fetch.ts index 7ab68d2e40eaa..62e5d7928712f 100644 --- a/cli/js/web/fetch.ts +++ b/cli/js/web/fetch.ts @@ -60,6 +60,7 @@ class Body implements domTypes.Body, domTypes.ReadableStream, io.ReadCloser { return this._data; } + // eslint-disable-next-line require-await async arrayBuffer(): Promise { // If we've already bufferred the response, just return it. if (this._data != null) { @@ -223,11 +224,12 @@ class Body implements domTypes.Body, domTypes.ReadableStream, io.ReadCloser { return read(this.rid, p); } - close(): void { + close(): Promise { close(this.rid); + return Promise.resolve(); } - async cancel(): Promise { + cancel(): Promise { return notImplemented(); } @@ -346,7 +348,7 @@ export class Response implements domTypes.Response { return false; } - async arrayBuffer(): Promise { + arrayBuffer(): Promise { /* You have to do the null check here and not in the function because * otherwise TS complains about this.body potentially being null */ if (this.bodyViewable() || this.body == null) { @@ -355,14 +357,14 @@ export class Response implements domTypes.Response { return this.body.arrayBuffer(); } - async blob(): Promise { + blob(): Promise { if (this.bodyViewable() || this.body == null) { return Promise.reject(new Error("Response body is null")); } return this.body.blob(); } - async formData(): Promise { + formData(): Promise { if (this.bodyViewable() || this.body == null) { return Promise.reject(new Error("Response body is null")); } @@ -370,14 +372,14 @@ export class Response implements domTypes.Response { } // eslint-disable-next-line @typescript-eslint/no-explicit-any - async json(): Promise { + json(): Promise { if (this.bodyViewable() || this.body == null) { return Promise.reject(new Error("Response body is null")); } return this.body.json(); } - async text(): Promise { + text(): Promise { if (this.bodyViewable() || this.body == null) { return Promise.reject(new Error("Response body is null")); } @@ -437,7 +439,7 @@ export class Response implements domTypes.Response { } } -async function sendFetchReq( +function sendFetchReq( url: string, method: string | null, headers: domTypes.Headers | null, diff --git a/cli/tests/018_async_catch.ts b/cli/tests/018_async_catch.ts index 0d034d798990b..a16f11696bc57 100644 --- a/cli/tests/018_async_catch.ts +++ b/cli/tests/018_async_catch.ts @@ -1,4 +1,4 @@ -async function fn(): Promise { +function fn(): Promise { throw new Error("message"); } async function call(): Promise { diff --git a/cli/tests/async_error.ts b/cli/tests/async_error.ts index 81c983a504ab4..b37369bac7fdf 100644 --- a/cli/tests/async_error.ts +++ b/cli/tests/async_error.ts @@ -1,4 +1,5 @@ console.log("hello"); +// eslint-disable-next-line require-await const foo = async (): Promise => { console.log("before error"); throw Error("error"); diff --git a/cli/tests/async_error.ts.out b/cli/tests/async_error.ts.out index d07ba8cfe0135..6e22799c27f77 100644 --- a/cli/tests/async_error.ts.out +++ b/cli/tests/async_error.ts.out @@ -2,10 +2,10 @@ before error world error: Uncaught Error: error -[WILDCARD]tests/async_error.ts:4:9 +[WILDCARD]tests/async_error.ts:5:9 -4 throw Error("error"); +5 throw Error("error"); ^ - at foo ([WILDCARD]tests/async_error.ts:4:9) - at [WILDCARD]tests/async_error.ts:7:1 + at foo ([WILDCARD]tests/async_error.ts:5:9) + at [WILDCARD]tests/async_error.ts:8:1 diff --git a/cli/tests/permission_test.ts b/cli/tests/permission_test.ts index 763e429b6270f..11b95cf3aa722 100644 --- a/cli/tests/permission_test.ts +++ b/cli/tests/permission_test.ts @@ -3,8 +3,9 @@ const { args, listen, env, exit, makeTempDirSync, readFileSync, run } = Deno; const name = args[0]; const test: { [key: string]: Function } = { - async readRequired(): Promise { + readRequired(): Promise { readFileSync("README.md"); + return Promise.resolve(); }, writeRequired(): void { makeTempDirSync(); diff --git a/cli/tests/top_level_for_await.js b/cli/tests/top_level_for_await.js index fa3b496a8cb73..54742ce5208a7 100644 --- a/cli/tests/top_level_for_await.js +++ b/cli/tests/top_level_for_await.js @@ -1,4 +1,4 @@ -async function* asyncGenerator() { +function* asyncGenerator() { let i = 0; while (i < 3) { yield i++; diff --git a/cli/tests/top_level_for_await.ts b/cli/tests/top_level_for_await.ts index 9179322d78f4b..92d8af30a4f5c 100644 --- a/cli/tests/top_level_for_await.ts +++ b/cli/tests/top_level_for_await.ts @@ -1,3 +1,4 @@ +// eslint-disable-next-line require-await async function* asyncGenerator(): AsyncIterableIterator { let i = 0; while (i < 3) { diff --git a/core/examples/http_bench.js b/core/examples/http_bench.js index 4314ba680f431..72f53550d9482 100644 --- a/core/examples/http_bench.js +++ b/core/examples/http_bench.js @@ -84,7 +84,7 @@ function listen() { } /** Accepts a connection, returns rid. */ -async function accept(rid) { +function accept(rid) { return sendAsync(ops["accept"], rid); } @@ -92,12 +92,12 @@ async function accept(rid) { * Reads a packet from the rid, presumably an http request. data is ignored. * Returns bytes read. */ -async function read(rid, data) { +function read(rid, data) { return sendAsync(ops["read"], rid, data); } /** Writes a fixed HTTP response to the socket rid. Returns bytes written. */ -async function write(rid, data) { +function write(rid, data) { return sendAsync(ops["write"], rid, data); } diff --git a/std/encoding/binary_test.ts b/std/encoding/binary_test.ts index 936fcbb6368cd..54f8cbded5f3f 100644 --- a/std/encoding/binary_test.ts +++ b/std/encoding/binary_test.ts @@ -24,12 +24,12 @@ Deno.test(async function testGetNBytes(): Promise { Deno.test(async function testGetNBytesThrows(): Promise { const data = new Uint8Array([1, 2, 3, 4]); const buff = new Deno.Buffer(data.buffer); - assertThrowsAsync(async () => { + await assertThrowsAsync(async () => { await getNBytes(buff, 8); }, Deno.errors.UnexpectedEof); }); -Deno.test(async function testPutVarbig(): Promise { +Deno.test(function testPutVarbig(): void { const buff = new Uint8Array(8); putVarbig(buff, 0xffeeddccbbaa9988n); assertEquals( @@ -38,7 +38,7 @@ Deno.test(async function testPutVarbig(): Promise { ); }); -Deno.test(async function testPutVarbigLittleEndian(): Promise { +Deno.test(function testPutVarbigLittleEndian(): void { const buff = new Uint8Array(8); putVarbig(buff, 0x8899aabbccddeeffn, { endian: "little" }); assertEquals( @@ -47,13 +47,13 @@ Deno.test(async function testPutVarbigLittleEndian(): Promise { ); }); -Deno.test(async function testPutVarnum(): Promise { +Deno.test(function testPutVarnum(): void { const buff = new Uint8Array(4); putVarnum(buff, 0xffeeddcc); assertEquals(buff, new Uint8Array([0xff, 0xee, 0xdd, 0xcc])); }); -Deno.test(async function testPutVarnumLittleEndian(): Promise { +Deno.test(function testPutVarnumLittleEndian(): void { const buff = new Uint8Array(4); putVarnum(buff, 0xccddeeff, { endian: "little" }); assertEquals(buff, new Uint8Array([0xff, 0xee, 0xdd, 0xcc])); diff --git a/std/encoding/yaml/example/sample_document.ts b/std/encoding/yaml/example/sample_document.ts index c9372e8ec3974..da969d6794dbc 100644 --- a/std/encoding/yaml/example/sample_document.ts +++ b/std/encoding/yaml/example/sample_document.ts @@ -5,7 +5,7 @@ import { parse } from "../../yaml.ts"; const { readFileSync, cwd } = Deno; -(async () => { +(() => { const yml = readFileSync(`${cwd()}/example/sample_document.yml`); const document = new TextDecoder().decode(yml); diff --git a/std/examples/chat/server.ts b/std/examples/chat/server.ts index 3c968e44e174b..08aede05bbc6d 100644 --- a/std/examples/chat/server.ts +++ b/std/examples/chat/server.ts @@ -8,7 +8,7 @@ import { const clients = new Map(); let clientId = 0; -async function dispatch(msg: string): Promise { +function dispatch(msg: string): void { for (const client of clients.values()) { client.send(msg); } diff --git a/std/examples/chat/server_test.ts b/std/examples/chat/server_test.ts index 899eb1b322e02..0d21b3787833b 100644 --- a/std/examples/chat/server_test.ts +++ b/std/examples/chat/server_test.ts @@ -18,7 +18,7 @@ async function startServer(): Promise { const r = new TextProtoReader(new BufReader(server.stdout)); const s = await r.readLine(); assert(s !== Deno.EOF && s.includes("chat server starting")); - } catch { + } catch (err) { server.stdout!.close(); server.close(); } diff --git a/std/fs/copy_test.ts b/std/fs/copy_test.ts index fb8827f0c7493..9ba5f2b2135de 100644 --- a/std/fs/copy_test.ts +++ b/std/fs/copy_test.ts @@ -17,10 +17,7 @@ const testdataDir = path.resolve("fs", "testdata"); // TODO(axetroy): Add test for Windows once symlink is implemented for Windows. const isWindows = Deno.build.os === "win"; -async function testCopy( - name: string, - cb: (tempDir: string) => Promise -): Promise { +function testCopy(name: string, cb: (tempDir: string) => Promise): void { Deno.test({ name, async fn(): Promise { diff --git a/std/fs/exists.ts b/std/fs/exists.ts index ae64cb1f3f826..f9e5a09253454 100644 --- a/std/fs/exists.ts +++ b/std/fs/exists.ts @@ -4,15 +4,16 @@ const { lstat, lstatSync } = Deno; * Test whether or not the given path exists by checking with the file system */ export async function exists(filePath: string): Promise { - return lstat(filePath) - .then((): boolean => true) - .catch((err: Error): boolean => { - if (err instanceof Deno.errors.NotFound) { - return false; - } + try { + await lstat(filePath); + return true; + } catch (err) { + if (err instanceof Deno.errors.NotFound) { + return false; + } - throw err; - }); + throw err; + } } /** diff --git a/std/fs/walk_test.ts b/std/fs/walk_test.ts index c2518cee32fd4..96bfcae67571e 100644 --- a/std/fs/walk_test.ts +++ b/std/fs/walk_test.ts @@ -5,11 +5,11 @@ import { assert, assertEquals, assertThrowsAsync } from "../testing/asserts.ts"; const isWindows = Deno.build.os == "win"; -export async function testWalk( +export function testWalk( setup: (arg0: string) => void | Promise, t: Deno.TestFunction, ignore = false -): Promise { +): void { const name = t.name; async function fn(): Promise { const origCwd = cwd(); diff --git a/std/http/file_server.ts b/std/http/file_server.ts index 18a68aa49d406..20d5d61e64ec7 100755 --- a/std/http/file_server.ts +++ b/std/http/file_server.ts @@ -158,17 +158,17 @@ async function serveDir( return res; } -async function serveFallback(req: ServerRequest, e: Error): Promise { +function serveFallback(req: ServerRequest, e: Error): Promise { if (e instanceof Deno.errors.NotFound) { - return { + return Promise.resolve({ status: 404, body: encoder.encode("Not found") - }; + }); } else { - return { + return Promise.resolve({ status: 500, body: encoder.encode("Internal server error") - }; + }); } } diff --git a/std/http/io.ts b/std/http/io.ts index 5518146a807dc..6d5d1f66537c8 100644 --- a/std/http/io.ts +++ b/std/http/io.ts @@ -7,8 +7,8 @@ import { STATUS_TEXT } from "./http_status.ts"; export function emptyReader(): Deno.Reader { return { - async read(_: Uint8Array): Promise { - return Deno.EOF; + read(_: Uint8Array): Promise { + return Promise.resolve(Deno.EOF); } }; } diff --git a/std/http/mock.ts b/std/http/mock.ts index 3a4eeed821e45..cee697bed8991 100644 --- a/std/http/mock.ts +++ b/std/http/mock.ts @@ -14,11 +14,11 @@ export function mockConn(base: Partial = {}): Deno.Conn { rid: -1, closeRead: (): void => {}, closeWrite: (): void => {}, - read: async (): Promise => { - return 0; + read: (): Promise => { + return Promise.resolve(0); }, - write: async (): Promise => { - return -1; + write: (): Promise => { + return Promise.resolve(-1); }, close: (): void => {}, ...base diff --git a/std/http/server_test.ts b/std/http/server_test.ts index 0a4986dcf14cd..2a7c46134b8db 100644 --- a/std/http/server_test.ts +++ b/std/http/server_test.ts @@ -68,7 +68,7 @@ test(async function responseWrite(): Promise { } }); -test(async function requestContentLength(): Promise { +test(function requestContentLength(): void { // Has content length { const req = new ServerRequest(); diff --git a/std/io/bufio.ts b/std/io/bufio.ts index 12b5c2d2b65a2..a944adfed4cb5 100644 --- a/std/io/bufio.ts +++ b/std/io/bufio.ts @@ -602,6 +602,7 @@ export async function* readStringDelim( } /** Read strings line-by-line from a Reader. */ +// eslint-disable-next-line require-await export async function* readLines( reader: Reader ): AsyncIterableIterator { diff --git a/std/io/bufio_test.ts b/std/io/bufio_test.ts index d925175f12bdc..ae38f66673f38 100644 --- a/std/io/bufio_test.ts +++ b/std/io/bufio_test.ts @@ -191,7 +191,7 @@ const testOutput = encoder.encode("0123456789abcdefghijklmnopqrstuvwxy"); class TestReader implements Reader { constructor(private data: Uint8Array, private stride: number) {} - async read(buf: Uint8Array): Promise { + read(buf: Uint8Array): Promise { let nread = this.stride; if (nread > this.data.byteLength) { nread = this.data.byteLength; @@ -200,11 +200,11 @@ class TestReader implements Reader { nread = buf.byteLength; } if (nread === 0) { - return Deno.EOF; + return Promise.resolve(Deno.EOF); } copyBytes(buf as Uint8Array, this.data); this.data = this.data.subarray(nread); - return nread; + return Promise.resolve(nread); } } diff --git a/std/io/iotest.ts b/std/io/iotest.ts index 1e922e33fe4fb..e2cf315aa8d81 100644 --- a/std/io/iotest.ts +++ b/std/io/iotest.ts @@ -10,14 +10,14 @@ type Reader = Deno.Reader; export class OneByteReader implements Reader { constructor(readonly r: Reader) {} - async read(p: Uint8Array): Promise { + read(p: Uint8Array): Promise { if (p.byteLength === 0) { - return 0; + return Promise.resolve(0); } if (!(p instanceof Uint8Array)) { throw Error("expected Uint8Array"); } - return this.r.read(p.subarray(0, 1)); + return Promise.resolve(this.r.read(p.subarray(0, 1))); } } @@ -27,12 +27,12 @@ export class OneByteReader implements Reader { export class HalfReader implements Reader { constructor(readonly r: Reader) {} - async read(p: Uint8Array): Promise { + read(p: Uint8Array): Promise { if (!(p instanceof Uint8Array)) { throw Error("expected Uint8Array"); } const half = Math.floor((p.byteLength + 1) / 2); - return this.r.read(p.subarray(0, half)); + return Promise.resolve(this.r.read(p.subarray(0, half))); } } @@ -43,11 +43,11 @@ export class TimeoutReader implements Reader { count = 0; constructor(readonly r: Reader) {} - async read(p: Uint8Array): Promise { + read(p: Uint8Array): Promise { this.count++; if (this.count === 2) { throw new Deno.errors.TimedOut(); } - return this.r.read(p); + return Promise.resolve(this.r.read(p)); } } diff --git a/std/io/ioutil_test.ts b/std/io/ioutil_test.ts index 261f4def0d3ba..3d85a0fa174a1 100644 --- a/std/io/ioutil_test.ts +++ b/std/io/ioutil_test.ts @@ -17,10 +17,10 @@ class BinaryReader implements Reader { constructor(private bytes: Uint8Array = new Uint8Array(0)) {} - async read(p: Uint8Array): Promise { + read(p: Uint8Array): Promise { p.set(this.bytes.subarray(this.index, p.byteLength)); this.index += p.byteLength; - return p.byteLength; + return Promise.resolve(p.byteLength); } } @@ -52,7 +52,7 @@ Deno.test(async function testReadLong2(): Promise { assertEquals(long, 0x12345678); }); -Deno.test(async function testSliceLongToBytes(): Promise { +Deno.test(function testSliceLongToBytes(): void { const arr = sliceLongToBytes(0x1234567890abcdef); const actual = readLong(new BufReader(new BinaryReader(new Uint8Array(arr)))); const expected = readLong( @@ -65,7 +65,7 @@ Deno.test(async function testSliceLongToBytes(): Promise { assertEquals(actual, expected); }); -Deno.test(async function testSliceLongToBytes2(): Promise { +Deno.test(function testSliceLongToBytes2(): void { const arr = sliceLongToBytes(0x12345678); assertEquals(arr, [0, 0, 0, 0, 0x12, 0x34, 0x56, 0x78]); }); diff --git a/std/io/readers.ts b/std/io/readers.ts index 5b1bf194853e2..2d81e246f14ba 100644 --- a/std/io/readers.ts +++ b/std/io/readers.ts @@ -9,14 +9,14 @@ export class StringReader implements Reader { constructor(private readonly s: string) {} - async read(p: Uint8Array): Promise { + read(p: Uint8Array): Promise { const n = Math.min(p.byteLength, this.buf.byteLength - this.offs); p.set(this.buf.slice(this.offs, this.offs + n)); this.offs += n; if (n === 0) { - return Deno.EOF; + return Promise.resolve(Deno.EOF); } - return n; + return Promise.resolve(n); } } diff --git a/std/io/writers.ts b/std/io/writers.ts index 722e0297f2471..b9a6a5e70ee9e 100644 --- a/std/io/writers.ts +++ b/std/io/writers.ts @@ -14,11 +14,11 @@ export class StringWriter implements Writer { this.byteLength += c.byteLength; } - async write(p: Uint8Array): Promise { + write(p: Uint8Array): Promise { this.chunks.push(p); this.byteLength += p.byteLength; this.cache = undefined; - return p.byteLength; + return Promise.resolve(p.byteLength); } toString(): string { diff --git a/std/node/_fs/_fs_close.ts b/std/node/_fs/_fs_close.ts index e19eb932ec251..4ec10eefb8d63 100644 --- a/std/node/_fs/_fs_close.ts +++ b/std/node/_fs/_fs_close.ts @@ -3,7 +3,7 @@ import { CallbackWithError } from "./_fs_common.ts"; export function close(fd: number, callback: CallbackWithError): void { - new Promise(async (resolve, reject) => { + new Promise((resolve, reject) => { try { Deno.close(fd); resolve(); diff --git a/std/node/_fs/_fs_close_test.ts b/std/node/_fs/_fs_close_test.ts index 2c71172488e35..7c6dd684cd806 100644 --- a/std/node/_fs/_fs_close_test.ts +++ b/std/node/_fs/_fs_close_test.ts @@ -16,7 +16,7 @@ test({ else resolve(); }); }) - .then(async () => { + .then(() => { assert(!Deno.resources()[file.rid]); }) .catch(() => { diff --git a/std/node/_fs/_fs_dir_test.ts b/std/node/_fs/_fs_dir_test.ts index 3b8c5b3413022..be276887bde1b 100644 --- a/std/node/_fs/_fs_dir_test.ts +++ b/std/node/_fs/_fs_dir_test.ts @@ -5,7 +5,7 @@ import Dirent from "./_fs_dirent.ts"; test({ name: "Closing current directory with callback is successful", - async fn() { + fn() { let calledBack = false; // eslint-disable-next-line @typescript-eslint/no-explicit-any new Dir(".").close((valOrErr: any) => { @@ -25,7 +25,7 @@ test({ test({ name: "Closing current directory synchronously works", - async fn() { + fn() { new Dir(".").closeSync(); } }); diff --git a/std/testing/bench.ts b/std/testing/bench.ts index 5cec3ea39687f..1c4b01c0b81f3 100644 --- a/std/testing/bench.ts +++ b/std/testing/bench.ts @@ -169,11 +169,12 @@ export async function runBenchmarks({ } /** Runs specified benchmarks if the enclosing script is main. */ -export async function runIfMain( +export function runIfMain( meta: ImportMeta, opts: BenchmarkRunOptions = {} ): Promise { if (meta.main) { return runBenchmarks(opts); } + return Promise.resolve(undefined); } diff --git a/std/textproto/reader_test.ts b/std/textproto/reader_test.ts index 7aead064b7745..f0ae63894ddec 100644 --- a/std/textproto/reader_test.ts +++ b/std/textproto/reader_test.ts @@ -21,9 +21,10 @@ function reader(s: string): TextProtoReader { test({ ignore: true, name: "[textproto] Reader : DotBytes", - async fn(): Promise { + fn(): Promise { const _input = "dotlines\r\n.foo\r\n..bar\n...baz\nquux\r\n\r\n.\r\nanot.her\r\n"; + return Promise.resolve(); } }); diff --git a/std/textproto/test.ts b/std/textproto/test.ts index 5b67bbf956415..9a992a2cf6f53 100644 --- a/std/textproto/test.ts +++ b/std/textproto/test.ts @@ -7,7 +7,7 @@ import { append } from "./mod.ts"; import { assertEquals } from "../testing/asserts.ts"; const { test } = Deno; -test(async function textprotoAppend(): Promise { +test(function textprotoAppend(): void { const enc = new TextEncoder(); const dec = new TextDecoder(); const u1 = enc.encode("Hello "); diff --git a/std/util/async_test.ts b/std/util/async_test.ts index 4607cf6cd2451..d81b52b43e795 100644 --- a/std/util/async_test.ts +++ b/std/util/async_test.ts @@ -3,17 +3,20 @@ const { test } = Deno; import { assert, assertEquals, assertStrictEq } from "../testing/asserts.ts"; import { collectUint8Arrays, deferred, MuxAsyncIterator } from "./async.ts"; -test(async function asyncDeferred(): Promise { +test(function asyncDeferred(): Promise { const d = deferred(); d.resolve(12); + return Promise.resolve(); }); +// eslint-disable-next-line require-await async function* gen123(): AsyncIterableIterator { yield 1; yield 2; yield 3; } +// eslint-disable-next-line require-await async function* gen456(): AsyncIterableIterator { yield 4; yield 5; @@ -47,6 +50,7 @@ test(async function collectUint8Arrays0(): Promise { test(async function collectUint8Arrays1(): Promise { const buf = new Uint8Array([1, 2, 3]); + // eslint-disable-next-line require-await async function* gen(): AsyncIterableIterator { yield buf; } @@ -56,6 +60,7 @@ test(async function collectUint8Arrays1(): Promise { }); test(async function collectUint8Arrays4(): Promise { + // eslint-disable-next-line require-await async function* gen(): AsyncIterableIterator { yield new Uint8Array([1, 2, 3]); yield new Uint8Array([]); diff --git a/std/ws/mod.ts b/std/ws/mod.ts index 809654a06e6d9..3332ed8dd22ba 100644 --- a/std/ws/mod.ts +++ b/std/ws/mod.ts @@ -322,7 +322,7 @@ class WebSocketImpl implements WebSocket { return d; } - async send(data: WebSocketMessage): Promise { + send(data: WebSocketMessage): Promise { const opcode = typeof data === "string" ? OpCode.TextFrame : OpCode.BinaryFrame; const payload = typeof data === "string" ? encode(data) : data; @@ -336,7 +336,7 @@ class WebSocketImpl implements WebSocket { return this.enqueue(frame); } - async ping(data: WebSocketMessage = ""): Promise { + ping(data: WebSocketMessage = ""): Promise { const payload = typeof data === "string" ? encode(data) : data; const frame = { isLastFrame: true, diff --git a/std/ws/test.ts b/std/ws/test.ts index 820fe1423d5ae..f1efa8e409b1b 100644 --- a/std/ws/test.ts +++ b/std/ws/test.ts @@ -126,7 +126,7 @@ test("[ws] read unmasked bigger binary frame", async () => { assertEquals(bin.payload.length, payloadLength); }); -test("[ws] createSecAccept", async () => { +test("[ws] createSecAccept", () => { const nonce = "dGhlIHNhbXBsZSBub25jZQ=="; const d = createSecAccept(nonce); assertEquals(d, "s3pPLMBiTxaQ9kYGzzhZRbK+xOo="); @@ -335,8 +335,8 @@ test("[ws] createSecKeyHasCorrectLength", () => { test("[ws] WebSocket should throw `Deno.errors.ConnectionReset` when peer closed connection without close frame", async () => { const buf = new Buffer(); const eofReader: Deno.Reader = { - async read(_: Uint8Array): Promise { - return Deno.EOF; + read(_: Uint8Array): Promise { + return Promise.resolve(Deno.EOF); } }; const conn = dummyConn(eofReader, buf); @@ -353,8 +353,8 @@ test("[ws] WebSocket should throw `Deno.errors.ConnectionReset` when peer closed test("[ws] WebSocket shouldn't throw `Deno.errors.UnexpectedEof` on recive()", async () => { const buf = new Buffer(); const eofReader: Deno.Reader = { - async read(_: Uint8Array): Promise { - return Deno.EOF; + read(_: Uint8Array): Promise { + return Promise.resolve(Deno.EOF); } }; const conn = dummyConn(eofReader, buf); @@ -372,7 +372,7 @@ test({ const buf = new Buffer(); let timer: number | undefined; const lazyWriter: Deno.Writer = { - async write(_: Uint8Array): Promise { + write(_: Uint8Array): Promise { return new Promise(resolve => { timer = setTimeout(() => resolve(0), 1000); }); diff --git a/tools/node_tcp_promise.js b/tools/node_tcp_promise.js index 547d97845056d..d522f1751a348 100644 --- a/tools/node_tcp_promise.js +++ b/tools/node_tcp_promise.js @@ -8,11 +8,11 @@ const response = Buffer.from( "HTTP/1.1 200 OK\r\nContent-Length: 12\r\n\r\nHello World\n" ); -async function write(socket, buffer) { +function write(socket, buffer) { const p = new Promise((resolve, _) => { socket.write(buffer, resolve); }); - return p; + return Promise.resolve(p); } Server(async socket => { @@ -20,6 +20,6 @@ Server(async socket => { socket.destroy(); }); for await (const _ of socket) { - write(socket, response); + await write(socket, response); } }).listen(port);