本文整理汇总了TypeScript中vs/base/node/storage.Storage类的典型用法代码示例。如果您正苦于以下问题:TypeScript Storage类的具体用法?TypeScript Storage怎么用?TypeScript Storage使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Storage类的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());
});
开发者ID:DonJayamanne,项目名称:vscode,代码行数:53,代码来源:storage.test.ts
示例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());
});
开发者ID:,项目名称:,代码行数:50,代码来源:
注:本文中的vs/base/node/storage.Storage类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论