@palgroup/simstream 0.9.0 → 0.10.0
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/dist/index.d.ts +11 -0
- package/dist/index.js +25 -0
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -301,6 +301,17 @@ export declare class SimStream {
|
|
|
301
301
|
* because the server is the one that knows how quickly the queue is moving.
|
|
302
302
|
*/
|
|
303
303
|
startSession(opts?: StartOptions): Promise<Session>;
|
|
304
|
+
/**
|
|
305
|
+
* Claim a simulator, or take a place in line and hand the ticket back rather than wait on it.
|
|
306
|
+
*
|
|
307
|
+
* startSession({ wait: true }) waits inside the call, which suits a script and not a service: a server that answers a
|
|
308
|
+
* person while they wait keeps the TICKET — in its own store, across its own restarts — and collects it with
|
|
309
|
+
* pollTicket. The session request is the same one startSession sends, with a place in line always asked for.
|
|
310
|
+
*/
|
|
311
|
+
requestSession(opts?: Omit<StartOptions, 'wait' | 'timeoutMs' | 'signal' | 'onQueue'>): Promise<Session | {
|
|
312
|
+
ticket: string;
|
|
313
|
+
position: number;
|
|
314
|
+
}>;
|
|
304
315
|
/** Where a queued session got to, without waiting for it. */
|
|
305
316
|
pollTicket(ticket: string): Promise<Session | {
|
|
306
317
|
position: number;
|
package/dist/index.js
CHANGED
|
@@ -73,6 +73,31 @@ class SimStream {
|
|
|
73
73
|
}
|
|
74
74
|
throw await this.errorFor(res);
|
|
75
75
|
}
|
|
76
|
+
/**
|
|
77
|
+
* Claim a simulator, or take a place in line and hand the ticket back rather than wait on it.
|
|
78
|
+
*
|
|
79
|
+
* startSession({ wait: true }) waits inside the call, which suits a script and not a service: a server that answers a
|
|
80
|
+
* person while they wait keeps the TICKET — in its own store, across its own restarts — and collects it with
|
|
81
|
+
* pollTicket. The session request is the same one startSession sends, with a place in line always asked for.
|
|
82
|
+
*/
|
|
83
|
+
async requestSession(opts = {}) {
|
|
84
|
+
const res = await this.request('POST', this.sessionUrl(opts.ttl), {
|
|
85
|
+
app: opts.app,
|
|
86
|
+
build: opts.build,
|
|
87
|
+
channel: opts.channel,
|
|
88
|
+
launch: opts.launch,
|
|
89
|
+
mode: opts.mode,
|
|
90
|
+
queue: true,
|
|
91
|
+
device: opts.device,
|
|
92
|
+
});
|
|
93
|
+
if (res.status === 200)
|
|
94
|
+
return (await res.json());
|
|
95
|
+
if (res.status === 202) {
|
|
96
|
+
const queued = (await res.json());
|
|
97
|
+
return { ticket: queued.ticket, position: queued.position };
|
|
98
|
+
}
|
|
99
|
+
throw await this.errorFor(res);
|
|
100
|
+
}
|
|
76
101
|
/** Where a queued session got to, without waiting for it. */
|
|
77
102
|
async pollTicket(ticket) {
|
|
78
103
|
const res = await this.request('GET', `/api/session?ticket=${encodeURIComponent(ticket)}`);
|