• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

microsoft / botbuilder-js / 11576939296

29 Oct 2024 03:15PM UTC coverage: 84.703% (-0.5%) from 85.23%
11576939296

Pull #4774

github

web-flow
Merge fcec82c6b into 6ef82744a
Pull Request #4774: refactor: [#4684] Replace browserify with tsup

8186 of 10820 branches covered (75.66%)

Branch coverage included in aggregate %.

2 of 2 new or added lines in 1 file covered. (100.0%)

23 existing lines in 13 files now uncovered.

20514 of 23063 relevant lines covered (88.95%)

7295.62 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

86.67
/libraries/botframework-streaming/src/payloads/requestManager.ts
1
/**
8✔
2
 * @module botframework-streaming
3
 */
4
/**
5
 * Copyright (c) Microsoft Corporation. All rights reserved.
6
 * Licensed under the MIT License.
7
 */
8
import { IReceiveResponse } from '../interfaces';
9

10
/**
11
 * A streaming pending request.
12
 */
13
class PendingRequest {
2✔
14
    requestId: string;
15
    resolve: (response: IReceiveResponse) => void;
16
    // eslint-disable-next-line @typescript-eslint/no-explicit-any
17
    reject: (reason?: any) => void;
18
}
19

20
/**
21
 * Orchestrates and manages pending streaming requests.
22
 */
23
export class RequestManager {
2✔
24
    private readonly _pendingRequests: Record<string, PendingRequest> = {};
99✔
25

26
    /**
27
     * Gets the count of the pending requests.
28
     *
29
     * @returns Number with the pending requests count.
30
     */
31
    pendingRequestCount(): number {
32
        return Object.keys(this._pendingRequests).length;
8✔
33
    }
34

35
    /**
36
     * Signal fired when all response tasks have completed.
37
     *
38
     * @param requestId The ID of the StreamingRequest.
39
     * @param response The [IReceiveResponse](xref:botframework-streaming.IReceiveResponse) in response to the request.
40
     * @returns A Promise that when completed returns `true` if the `requestId`'s pending response task was completed, otherwise `false`.
41
     */
UNCOV
42
    async signalResponse(requestId: string, response: IReceiveResponse): Promise<boolean> {
×
43
        const pendingRequest = this._pendingRequests[requestId];
14✔
44

45
        if (pendingRequest) {
14✔
46
            pendingRequest.resolve(response);
10!
47
            delete this._pendingRequests[requestId];
10✔
48

49
            return true;
10✔
50
        }
51

52
        return false;
4✔
53
    }
54

55
    /**
56
     * Constructs and returns a response for this request.
57
     *
58
     * @param requestId The ID of the StreamingRequest being responded to.
59
     * @returns The response to the specified request.
60
     */
61
    getResponse(requestId: string): Promise<IReceiveResponse> {
62
        let pendingRequest = this._pendingRequests[requestId];
32✔
63

64
        if (pendingRequest) {
32!
65
            return Promise.reject(`requestId '${requestId}' already exists in RequestManager`);
2✔
66
        }
67

68
        pendingRequest = new PendingRequest();
30✔
69
        pendingRequest.requestId = requestId;
30✔
70

71
        const promise = new Promise<IReceiveResponse>((resolve, reject): void => {
30✔
72
            pendingRequest.resolve = resolve;
30✔
73
            pendingRequest.reject = reject;
30✔
74
        });
75

76
        this._pendingRequests[requestId] = pendingRequest;
30✔
77

78
        return promise;
30✔
79
    }
80

81
    /**
82
     * Rejects all requests pending a response.
83
     *
84
     * @param reason The reason for rejection.
85
     */
86
    rejectAllResponses(reason?: Error): void {
87
        Object.entries(this._pendingRequests).forEach(([requestId, { reject }]) => {
40✔
88
            reject(reason);
16✔
89

90
            delete this._pendingRequests[requestId];
16✔
91
        });
92
    }
93
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc