Skip to content

Commit

Permalink
CCA: ESLint: Fix floating promise warning in models/video_saver.ts
Browse files Browse the repository at this point in the history
This push the async / await upward one level, so the total amount of
lint warning doesn't reduce by much.

`cca.py lint --eslintrc .eslintrc_floating_promise.js` error count goes
down from 107 to 106.

Bug: b:172336355
Test: cca.py lint --eslintrc .eslintrc_floating_promise.js
Change-Id: I8a351af915e4d53ca405be8fd69a9d08ea1b0121
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4299089
Commit-Queue: Pi-Hsun Shih <pihsun@chromium.org>
Reviewed-by: Shik Chen <shik@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1115582}
  • Loading branch information
peter50216 authored and Chromium LUCI CQ committed Mar 10, 2023
1 parent ac08161 commit 05ce3fb
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 8 deletions.
6 changes: 4 additions & 2 deletions ash/webui/camera_app_ui/resources/js/async_job_queue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

import {Awaitable} from './type.js';

/**
* Asynchronous job queue.
*/
Expand All @@ -13,7 +15,7 @@ export class AsyncJobQueue {
*
* @return Resolved with the job return value when the job is finished.
*/
push<T>(job: () => Promise<T>): Promise<T> {
push<T>(job: () => Awaitable<T>): Promise<T> {
const promise =
this.promise.catch(() => {/* ignore error from previous job */})
.then(job);
Expand Down Expand Up @@ -45,7 +47,7 @@ export class ClearableAsyncJobQueue {
* @return Resolved with the job return value when the job is finished, or
* null if the job is cleared.
*/
push<T>(job: () => Promise<T>): Promise<T|null> {
push<T>(job: () => Awaitable<T>): Promise<T|null> {
const promise =
this.promise.catch(() => {/* ignore error from previous job */})
.then(() => {
Expand Down
3 changes: 2 additions & 1 deletion ash/webui/camera_app_ui/resources/js/models/async_writer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,14 @@

import {assert} from '../assert.js';
import {AsyncJobQueue} from '../async_job_queue.js';
import {Awaitable} from '../type.js';

/**
* Represents a set of operations of a file-like writable stream. The seek and
* close operations are optional.
*/
export interface AsyncOps {
write(blob: Blob): Promise<void>;
write(blob: Blob): Awaitable<void>;
seek: ((offset: number) => Promise<void>)|null;
close: (() => Promise<void>)|null;
}
Expand Down
10 changes: 5 additions & 5 deletions ash/webui/camera_app_ui/resources/js/models/video_saver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,8 @@ export class VideoSaver {
/**
* Writes video data to result video.
*/
write(blob: Blob): void {
this.processor.write(blob);
async write(blob: Blob): Promise<void> {
await this.processor.write(blob);
}

/**
Expand Down Expand Up @@ -131,8 +131,8 @@ export class GifSaver {
private readonly blobs: Blob[],
private readonly processor: Comlink.Remote<VideoProcessor>) {}

write(frame: Uint8ClampedArray): void {
this.processor.write(new Blob([frame]));
async write(frame: Uint8ClampedArray): Promise<void> {
await this.processor.write(new Blob([frame]));
}

/**
Expand All @@ -149,7 +149,7 @@ export class GifSaver {
static async create(resolution: Resolution): Promise<GifSaver> {
const blobs: Blob[] = [];
const writer = new AsyncWriter({
async write(blob) {
write(blob) {
blobs.push(blob);
},
seek: null,
Expand Down
2 changes: 2 additions & 0 deletions ash/webui/camera_app_ui/resources/js/type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -500,3 +500,5 @@ export enum LowStorageDialogType {
AUTO_STOP = 'auto-stop',
CANNOT_START = 'cannot-start',
}

export type Awaitable<T> = PromiseLike<T>|T;

0 comments on commit 05ce3fb

Please sign in to comment.