@http-forge/core 0.4.5 → 0.4.7

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/README.md CHANGED
@@ -267,6 +267,31 @@ const forge = ForgeContainer.create({ scriptScope: 'isolated' });
267
267
 
268
268
  Use `'isolated'` when importing Postman collections whose scripts re-declare the same identifiers at multiple levels, which would otherwise throw `Identifier already declared` in shared mode.
269
269
 
270
+ #### Async Script Execution (Event-Loop Draining)
271
+
272
+ Like Postman, scripts do **not** end when their synchronous code returns. After the sync body completes, the core keeps the sandbox alive and drains pending timers (`setTimeout`/`setInterval`) and microtasks (un-awaited `Promise`s), then commits variable scopes — so deferred `pm.globals` / `pm.environment` / `pm.variables` writes are visible to the next request **without** `await`.
273
+
274
+ ```typescript
275
+ // Post-response script — committed for the next request, no await required
276
+ setTimeout(() => pm.globals.set('authToken', generateToken()), 1500);
277
+ ```
278
+
279
+ The drain is bounded by `scripts.timeout` (the `scriptTimeout` SDK option), default **5000 ms**, which caps **both** synchronous CPU time and the async-drain window:
280
+
281
+ ```typescript
282
+ const forge = ForgeContainer.create({ scriptTimeout: 10000 });
283
+ ```
284
+
285
+ | Behavior | Notes |
286
+ |----------|-------|
287
+ | Sandbox kept alive after sync return | Pending timers/microtasks drained before the request advances |
288
+ | Deferred `pm.*` writes committed | Visible to the next request without `await` |
289
+ | Errors in timer/Promise callbacks | Reported as a console error, **non-fatal** — the request/test is not failed |
290
+ | Runaway timers | A never-clearing `setInterval` or infinite timer loop is force-cancelled at the timeout, with a warning |
291
+ | No async work | Returns immediately; draining adds no measurable latency |
292
+
293
+ **Divergences from Postman:** uses real Node timers with a poll-based wall-clock drain (no exact pending-promise count, so pathological microtask recursion is bounded by the budget rather than a precise idle signal); a single `scripts.timeout` bounds both CPU time and the async window.
294
+
270
295
  ### Environment Management
271
296
 
272
297
  ```typescript
@@ -431,7 +456,7 @@ interface ForgeContainerOptions {
431
456
 
432
457
  // Script Settings
433
458
  scriptRunner?: IScriptRunner; // Custom script runner
434
- scriptTimeout?: number; // Script timeout (ms)
459
+ scriptTimeout?: number; // Script budget (ms); caps CPU time + async-drain window. Default 5000
435
460
 
436
461
  // History
437
462
  enableHistory?: boolean; // Enable request history