testing function sum and freeze

This commit is contained in:
Sebastian 2022-12-21 16:36:24 -03:00
parent 7873571d22
commit a73d24759c
No known key found for this signature in database
GPG Key ID: BE4FF68352439FC1
3 changed files with 44 additions and 0 deletions

View File

@ -197,6 +197,30 @@ export function View({
<i18n.Translate>run gc</i18n.Translate>
</Button>
</Grid>
<Grid item>
<Button
variant="contained"
onClick={() => {
return api.background.call("sum", [1, 2, 3]).then((r) => {
console.log("SUM", r);
});
}}
>
<i18n.Translate>sum 123</i18n.Translate>
</Button>
</Grid>
<Grid item>
<Button
variant="contained"
onClick={() => {
return api.background.call("freeze", 5000).then(() => {
console.log("WAIT");
});
}}
>
<i18n.Translate>freeze 5000</i18n.Translate>
</Button>
</Grid>
<Grid item>
<Button
variant="contained"

View File

@ -53,6 +53,14 @@ export interface ExtendedPermissionsResponse {
}
export interface BackgroundOperations {
freeze: {
request: number;
response: void;
};
sum: {
request: number[],
response: number,
}
resetDb: {
request: void;
response: void;

View File

@ -162,7 +162,19 @@ async function toggleHeaderListener(
return { newValue: false };
}
function freeze(time: number): Promise<void> {
return new Promise((res, rej) => {
setTimeout(res, time)
})
}
async function sum(ns: Array<number>): Promise<number> {
return ns.reduce((prev, cur) => prev + cur, 0)
}
const backendHandlers: BackendHandlerType = {
freeze,
sum,
containsHeaderListener,
getDiagnostics,
resetDb,