mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-02-16 10:58:30 -05:00
Merge from master
This commit is contained in:
@@ -2,13 +2,10 @@
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the Source EULA. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
'use strict';
|
||||
|
||||
import * as assert from 'assert';
|
||||
import { Event, Emitter, debounceEvent, EventBufferer, once, fromPromise, stopwatch, buffer, echo, EventMultiplexer, latch, AsyncEmitter, IWaitUntil } from 'vs/base/common/event';
|
||||
import { IDisposable } from 'vs/base/common/lifecycle';
|
||||
import * as Errors from 'vs/base/common/errors';
|
||||
import { TPromise } from 'vs/base/common/winjs.base';
|
||||
import { timeout } from 'vs/base/common/async';
|
||||
|
||||
namespace Samples {
|
||||
@@ -84,7 +81,7 @@ suite('Event', function () {
|
||||
assert.equal(counter.count, 2);
|
||||
});
|
||||
|
||||
test('onFirstAdd|onLastRemove', function () {
|
||||
test('onFirstAdd|onLastRemove', () => {
|
||||
|
||||
let firstCount = 0;
|
||||
let lastCount = 0;
|
||||
@@ -109,7 +106,7 @@ suite('Event', function () {
|
||||
assert.equal(lastCount, 1);
|
||||
});
|
||||
|
||||
test('throwingListener', function () {
|
||||
test('throwingListener', () => {
|
||||
const origErrorHandler = Errors.errorHandler.getUnexpectedErrorHandler();
|
||||
Errors.setUnexpectedErrorHandler(() => null);
|
||||
|
||||
@@ -184,7 +181,7 @@ suite('Event', function () {
|
||||
doc.setText('3');
|
||||
});
|
||||
|
||||
test('Debounce Event - leading', function () {
|
||||
test('Debounce Event - leading', async function () {
|
||||
const emitter = new Emitter<void>();
|
||||
let debounced = debounceEvent(emitter.event, (l, e) => e, 0, /*leading=*/true);
|
||||
|
||||
@@ -196,12 +193,11 @@ suite('Event', function () {
|
||||
// If the source event is fired once, the debounced (on the leading edge) event should be fired only once
|
||||
emitter.fire();
|
||||
|
||||
return TPromise.timeout(1).then(() => {
|
||||
assert.equal(calls, 1);
|
||||
});
|
||||
await timeout(1);
|
||||
assert.equal(calls, 1);
|
||||
});
|
||||
|
||||
test('Debounce Event - leading', function () {
|
||||
test('Debounce Event - leading', async function () {
|
||||
const emitter = new Emitter<void>();
|
||||
let debounced = debounceEvent(emitter.event, (l, e) => e, 0, /*leading=*/true);
|
||||
|
||||
@@ -214,9 +210,8 @@ suite('Event', function () {
|
||||
emitter.fire();
|
||||
emitter.fire();
|
||||
emitter.fire();
|
||||
return TPromise.timeout(1).then(() => {
|
||||
assert.equal(calls, 2);
|
||||
});
|
||||
await timeout(1);
|
||||
assert.equal(calls, 2);
|
||||
});
|
||||
|
||||
test('Emitter - In Order Delivery', function () {
|
||||
@@ -414,23 +409,22 @@ suite('Event utils', () => {
|
||||
|
||||
suite('fromPromise', () => {
|
||||
|
||||
test('should emit when done', () => {
|
||||
test('should emit when done', async () => {
|
||||
let count = 0;
|
||||
|
||||
const event = fromPromise(TPromise.as(null));
|
||||
const event = fromPromise(Promise.resolve(null));
|
||||
event(() => count++);
|
||||
|
||||
assert.equal(count, 0);
|
||||
|
||||
return TPromise.timeout(10).then(() => {
|
||||
assert.equal(count, 1);
|
||||
});
|
||||
await timeout(10);
|
||||
assert.equal(count, 1);
|
||||
});
|
||||
|
||||
test('should emit when done - setTimeout', async () => {
|
||||
let count = 0;
|
||||
|
||||
const promise = TPromise.timeout(5);
|
||||
const promise = timeout(5);
|
||||
const event = fromPromise(promise);
|
||||
event(() => count++);
|
||||
|
||||
@@ -446,7 +440,7 @@ suite('Event utils', () => {
|
||||
const emitter = new Emitter<void>();
|
||||
const event = stopwatch(emitter.event);
|
||||
|
||||
return new TPromise((c, e) => {
|
||||
return new Promise((c, e) => {
|
||||
event(duration => {
|
||||
try {
|
||||
assert(duration > 0);
|
||||
@@ -486,7 +480,7 @@ suite('Event utils', () => {
|
||||
assert.deepEqual(result, [1, 2, 3, 4]);
|
||||
});
|
||||
|
||||
test('should buffer events on next tick', () => {
|
||||
test('should buffer events on next tick', async () => {
|
||||
const result: number[] = [];
|
||||
const emitter = new Emitter<number>();
|
||||
const event = emitter.event;
|
||||
@@ -500,14 +494,12 @@ suite('Event utils', () => {
|
||||
const listener = bufferedEvent(num => result.push(num));
|
||||
assert.deepEqual(result, []);
|
||||
|
||||
return TPromise.timeout(10).then(() => {
|
||||
emitter.fire(4);
|
||||
assert.deepEqual(result, [1, 2, 3, 4]);
|
||||
|
||||
listener.dispose();
|
||||
emitter.fire(5);
|
||||
assert.deepEqual(result, [1, 2, 3, 4]);
|
||||
});
|
||||
await timeout(10);
|
||||
emitter.fire(4);
|
||||
assert.deepEqual(result, [1, 2, 3, 4]);
|
||||
listener.dispose();
|
||||
emitter.fire(5);
|
||||
assert.deepEqual(result, [1, 2, 3, 4]);
|
||||
});
|
||||
|
||||
test('should fire initial buffer events', () => {
|
||||
@@ -750,7 +742,7 @@ suite('Event utils', () => {
|
||||
});
|
||||
});
|
||||
|
||||
test('latch', function () {
|
||||
test('latch', () => {
|
||||
const emitter = new Emitter<number>();
|
||||
const event = latch(emitter.event);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user