當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript storage.Storage類代碼示例

本文整理匯總了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;未經允許,請勿轉載。