本文整理匯總了TypeScript中vs/base/node/storage.Storage.close方法的典型用法代碼示例。如果您正苦於以下問題:TypeScript Storage.close方法的具體用法?TypeScript Storage.close怎麽用?TypeScript Storage.close使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類vs/base/node/storage.Storage
的用法示例。
在下文中一共展示了Storage.close方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: test
test('close flushes data', async () => {
const storageDir = uniqueStorageDir();
await mkdirp(storageDir);
let storage = new Storage({ path: join(storageDir, 'storage.db') });
await storage.init();
const set1Promise = storage.set('foo', 'bar');
const set2Promise = storage.set('bar', 'foo');
equal(storage.get('foo'), 'bar');
equal(storage.get('bar'), 'foo');
let setPromiseResolved = false;
Promise.all([set1Promise, set2Promise]).then(() => setPromiseResolved = true);
await storage.close();
equal(setPromiseResolved, true);
storage = new Storage({ path: join(storageDir, 'storage.db') });
await storage.init();
equal(storage.get('foo'), 'bar');
equal(storage.get('bar'), 'foo');
await storage.close();
storage = new Storage({ path: join(storageDir, 'storage.db') });
await storage.init();
const delete1Promise = storage.delete('foo');
const delete2Promise = storage.delete('bar');
ok(!storage.get('foo'));
ok(!storage.get('bar'));
let deletePromiseResolved = false;
Promise.all([delete1Promise, delete2Promise]).then(() => deletePromiseResolved = true);
await storage.close();
equal(deletePromiseResolved, true);
storage = new Storage({ path: join(storageDir, 'storage.db') });
await storage.init();
ok(!storage.get('foo'));
ok(!storage.get('bar'));
await storage.close();
await del(storageDir, tmpdir());
});
示例2: test
test('multiple concurrent writes execute in sequence', async () => {
const storageDir = uniqueStorageDir();
await mkdirp(storageDir);
const storage = new Storage({ path: join(storageDir, 'storage.db') });
await storage.init();
storage.set('foo', 'bar');
storage.set('some/foo/path', 'some/bar/path');
await timeout(10);
storage.set('foo1', 'bar');
storage.set('some/foo1/path', 'some/bar/path');
await timeout(10);
storage.set('foo2', 'bar');
storage.set('some/foo2/path', 'some/bar/path');
await timeout(10);
storage.delete('foo1');
storage.delete('some/foo1/path');
await timeout(10);
storage.delete('foo4');
storage.delete('some/foo4/path');
await timeout(70);
storage.set('foo3', 'bar');
await storage.set('some/foo3/path', 'some/bar/path');
const items = await storage.getItems();
equal(items.get('foo'), 'bar');
equal(items.get('some/foo/path'), 'some/bar/path');
equal(items.has('foo1'), false);
equal(items.has('some/foo1/path'), false);
equal(items.get('foo2'), 'bar');
equal(items.get('some/foo2/path'), 'some/bar/path');
equal(items.get('foo3'), 'bar');
equal(items.get('some/foo3/path'), 'some/bar/path');
await storage.close();
await del(storageDir, tmpdir());
});