nerdbank-streams 2.11.86 → 2.12.74-alpha

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/src/Deferred.ts CHANGED
@@ -1,75 +1,75 @@
1
- /**
2
- * A TaskCompletionSource-like class that allows promises to be resolved or rejected whenever.
3
- */
4
- export class Deferred<T> {
5
- public readonly promise: Promise<T>
6
- private resolvePromise!: (value: T | PromiseLike<T>) => void
7
- private rejectPromise!: (reason?: any) => void
8
- private _isResolved: boolean = false
9
- private _isRejected: boolean = false
10
- private _error: any
11
-
12
- constructor(public state?: any) {
13
- this.promise = new Promise<T>((resolve, reject) => {
14
- this.resolvePromise = resolve
15
- this.rejectPromise = reject
16
- })
17
- }
18
-
19
- /**
20
- * Gets a value indicating whether this promise has been completed.
21
- */
22
- public get isCompleted() {
23
- return this._isResolved || this._isRejected
24
- }
25
-
26
- /**
27
- * Gets a value indicating whether this promise is resolved.
28
- */
29
- public get isResolved() {
30
- return this._isResolved
31
- }
32
-
33
- /**
34
- * Gets a value indicating whether this promise is rejected.
35
- */
36
- public get isRejected() {
37
- return this._isRejected
38
- }
39
-
40
- /**
41
- * Gets the reason for promise rejection, if applicable.
42
- */
43
- public get error() {
44
- return this._error
45
- }
46
-
47
- /**
48
- * Resolves the promise.
49
- * @param value The result of the promise.
50
- */
51
- public resolve(value: T | PromiseLike<T>): boolean {
52
- if (this.isCompleted) {
53
- return false
54
- }
55
-
56
- this.resolvePromise(value)
57
- this._isResolved = true
58
- return true
59
- }
60
-
61
- /**
62
- * Rejects the promise.
63
- * @param reason The reason for rejecting the promise.
64
- */
65
- public reject(reason?: any): boolean {
66
- if (this.isCompleted) {
67
- return false
68
- }
69
-
70
- this.rejectPromise(reason)
71
- this._error = reason
72
- this._isRejected = true
73
- return true
74
- }
75
- }
1
+ /**
2
+ * A TaskCompletionSource-like class that allows promises to be resolved or rejected whenever.
3
+ */
4
+ export class Deferred<T> {
5
+ public readonly promise: Promise<T>
6
+ private resolvePromise!: (value: T | PromiseLike<T>) => void
7
+ private rejectPromise!: (reason?: any) => void
8
+ private _isResolved: boolean = false
9
+ private _isRejected: boolean = false
10
+ private _error: any
11
+
12
+ constructor(public state?: any) {
13
+ this.promise = new Promise<T>((resolve, reject) => {
14
+ this.resolvePromise = resolve
15
+ this.rejectPromise = reject
16
+ })
17
+ }
18
+
19
+ /**
20
+ * Gets a value indicating whether this promise has been completed.
21
+ */
22
+ public get isCompleted() {
23
+ return this._isResolved || this._isRejected
24
+ }
25
+
26
+ /**
27
+ * Gets a value indicating whether this promise is resolved.
28
+ */
29
+ public get isResolved() {
30
+ return this._isResolved
31
+ }
32
+
33
+ /**
34
+ * Gets a value indicating whether this promise is rejected.
35
+ */
36
+ public get isRejected() {
37
+ return this._isRejected
38
+ }
39
+
40
+ /**
41
+ * Gets the reason for promise rejection, if applicable.
42
+ */
43
+ public get error() {
44
+ return this._error
45
+ }
46
+
47
+ /**
48
+ * Resolves the promise.
49
+ * @param value The result of the promise.
50
+ */
51
+ public resolve(value: T | PromiseLike<T>): boolean {
52
+ if (this.isCompleted) {
53
+ return false
54
+ }
55
+
56
+ this.resolvePromise(value)
57
+ this._isResolved = true
58
+ return true
59
+ }
60
+
61
+ /**
62
+ * Rejects the promise.
63
+ * @param reason The reason for rejecting the promise.
64
+ */
65
+ public reject(reason?: any): boolean {
66
+ if (this.isCompleted) {
67
+ return false
68
+ }
69
+
70
+ this.rejectPromise(reason)
71
+ this._error = reason
72
+ this._isRejected = true
73
+ return true
74
+ }
75
+ }
@@ -1,47 +1,47 @@
1
- import { ControlCode } from './ControlCode'
2
- import { requireInteger } from './Utilities'
3
- import { QualifiedChannelId } from './QualifiedChannelId'
4
-
5
- export class FrameHeader {
6
- private _channel?: QualifiedChannelId
7
-
8
- /**
9
- * Initializes a new instance of the `FrameHeader` class.
10
- * @param code The kind of frame this is.
11
- * @param channel The channel that this frame refers to or carries a payload for.
12
- */
13
- constructor(
14
- public readonly code: ControlCode,
15
- channel?: QualifiedChannelId
16
- ) {
17
- if (channel) {
18
- requireInteger('channelId', channel.id, 4, 'signed')
19
- }
20
-
21
- this.code = code
22
- this._channel = channel
23
- }
24
-
25
- /** The channel that this frame refers to or carries a payload for. */
26
- get channel(): QualifiedChannelId | undefined {
27
- return this._channel
28
- }
29
-
30
- /**
31
- * Gets the channel that this frame refers to or carries a payload for.
32
- */
33
- public get requiredChannel(): QualifiedChannelId {
34
- if (this.channel) {
35
- return this.channel
36
- }
37
-
38
- throw new Error('Expected channel not present in frame header.')
39
- }
40
-
41
- /** Changes the channel.source property to reflect the opposite perspective (i.e. remote and local values switch). */
42
- public flipChannelPerspective() {
43
- if (this._channel) {
44
- this._channel = { id: this._channel.id, source: this._channel.source * -1 }
45
- }
46
- }
47
- }
1
+ import { ControlCode } from './ControlCode'
2
+ import { requireInteger } from './Utilities'
3
+ import { QualifiedChannelId } from './QualifiedChannelId'
4
+
5
+ export class FrameHeader {
6
+ private _channel?: QualifiedChannelId
7
+
8
+ /**
9
+ * Initializes a new instance of the `FrameHeader` class.
10
+ * @param code The kind of frame this is.
11
+ * @param channel The channel that this frame refers to or carries a payload for.
12
+ */
13
+ constructor(
14
+ public readonly code: ControlCode,
15
+ channel?: QualifiedChannelId
16
+ ) {
17
+ if (channel) {
18
+ requireInteger('channelId', channel.id, 4, 'signed')
19
+ }
20
+
21
+ this.code = code
22
+ this._channel = channel
23
+ }
24
+
25
+ /** The channel that this frame refers to or carries a payload for. */
26
+ get channel(): QualifiedChannelId | undefined {
27
+ return this._channel
28
+ }
29
+
30
+ /**
31
+ * Gets the channel that this frame refers to or carries a payload for.
32
+ */
33
+ public get requiredChannel(): QualifiedChannelId {
34
+ if (this.channel) {
35
+ return this.channel
36
+ }
37
+
38
+ throw new Error('Expected channel not present in frame header.')
39
+ }
40
+
41
+ /** Changes the channel.source property to reflect the opposite perspective (i.e. remote and local values switch). */
42
+ public flipChannelPerspective() {
43
+ if (this._channel) {
44
+ this._channel = { id: this._channel.id, source: this._channel.source * -1 }
45
+ }
46
+ }
47
+ }
@@ -1,32 +1,32 @@
1
- import { Duplex, PassThrough } from 'stream'
2
-
3
- export class FullDuplexStream {
4
- // eslint-disable-next-line @typescript-eslint/naming-convention
5
- public static CreatePair(): { first: Duplex; second: Duplex } {
6
- const pass1 = new PassThrough()
7
- const pass2 = new PassThrough()
8
- return {
9
- first: FullDuplexStream.Splice(pass1, pass2),
10
- second: FullDuplexStream.Splice(pass2, pass1),
11
- }
12
- }
13
-
14
- // eslint-disable-next-line @typescript-eslint/naming-convention
15
- public static Splice(readable: NodeJS.ReadableStream, writable: NodeJS.WritableStream): Duplex {
16
- const duplex = new Duplex({
17
- write(chunk, encoding, callback) {
18
- writable.write(chunk, encoding, callback)
19
- },
20
-
21
- final(callback) {
22
- writable.end(callback)
23
- },
24
- })
25
-
26
- // All reads and events come directly from the readable stream.
27
- duplex.read = readable.read.bind(readable)
28
- duplex.on = readable.on.bind(readable) as any
29
-
30
- return duplex
31
- }
32
- }
1
+ import { Duplex, PassThrough } from 'stream'
2
+
3
+ export class FullDuplexStream {
4
+ // eslint-disable-next-line @typescript-eslint/naming-convention
5
+ public static CreatePair(): { first: Duplex; second: Duplex } {
6
+ const pass1 = new PassThrough()
7
+ const pass2 = new PassThrough()
8
+ return {
9
+ first: FullDuplexStream.Splice(pass1, pass2),
10
+ second: FullDuplexStream.Splice(pass2, pass1),
11
+ }
12
+ }
13
+
14
+ // eslint-disable-next-line @typescript-eslint/naming-convention
15
+ public static Splice(readable: NodeJS.ReadableStream, writable: NodeJS.WritableStream): Duplex {
16
+ const duplex = new Duplex({
17
+ write(chunk, encoding, callback) {
18
+ writable.write(chunk, encoding, callback)
19
+ },
20
+
21
+ final(callback) {
22
+ writable.end(callback)
23
+ },
24
+ })
25
+
26
+ // All reads and events come directly from the readable stream.
27
+ duplex.read = readable.read.bind(readable)
28
+ duplex.on = readable.on.bind(readable) as any
29
+
30
+ return duplex
31
+ }
32
+ }
@@ -1,19 +1,19 @@
1
- /**
2
- * Describes an offer for a channel.
3
- */
4
- export interface IChannelOfferEventArgs {
5
- /**
6
- * Gets the unique ID of the channel.
7
- */
8
- readonly id: number
9
-
10
- /**
11
- * Gets the name of the channel.
12
- */
13
- readonly name: string
14
-
15
- /**
16
- * Gets a value indicating whether the channel has already been accepted.
17
- */
18
- readonly isAccepted: boolean
19
- }
1
+ /**
2
+ * Describes an offer for a channel.
3
+ */
4
+ export interface IChannelOfferEventArgs {
5
+ /**
6
+ * Gets the unique ID of the channel.
7
+ */
8
+ readonly id: number
9
+
10
+ /**
11
+ * Gets the name of the channel.
12
+ */
13
+ readonly name: string
14
+
15
+ /**
16
+ * Gets a value indicating whether the channel has already been accepted.
17
+ */
18
+ readonly isAccepted: boolean
19
+ }
@@ -1,4 +1,4 @@
1
- export interface IDisposableObservable {
2
- readonly isDisposed: boolean
3
- dispose()
4
- }
1
+ export interface IDisposableObservable {
2
+ readonly isDisposed: boolean
3
+ dispose()
4
+ }