blob: 0ae9dbdf13793054742ced27543e9654465c72b2 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
|
'use strict';
import {forwardToDedicatedWorker, tryToCreateLock} from './bfcache-test-helpers.js';
export const createSAH = forwardToDedicatedWorker('createSAH');
export const releaseSAH = forwardToDedicatedWorker('releaseSAH');
export const createAndReleaseSAH =
forwardToDedicatedWorker('createAndReleaseSAH');
let openWFS;
export async function createWFS(mode, fileName) {
if (openWFS) {
throw new Error('Already have an open writable.');
}
openWFS = await tryToCreateLock(
fileName, fileHandle => fileHandle.createWritable({mode}));
return openWFS !== undefined;
}
export async function releaseWFS() {
if (!openWFS) {
throw new Error('No open writable.');
}
await openWFS.close();
openWFS = undefined;
}
export async function createAndReleaseWFS(mode, fileName) {
const wfsLock = await tryToCreateLock(
fileName, fileHandle => fileHandle.createWritable({mode}));
await wfsLock?.close();
return wfsLock !== undefined;
}
|