feat(eventual-send): Feature-flag track-turns
Introduces DEBUG=track-turns and TRACK_TURNS=enabled environment flags.
MODIFY
packages/eventual-send/src/track-turns.js
packages/eventual-send/src/track-turns.js
@@ -15,8 +15,17 @@ let hiddenPriorError;
let hiddenCurrentTurn = 0;
let hiddenCurrentEvent = 0;
+// TODO Use environment-options.js currently in ses/src after factoring it out
+// to a new package.
+const env = globalThis?.process?.env;
+
// Turn on if you seem to be losing error logging at the top of the event loop
-const VERBOSE = false;
+const VERBOSE = (env?.DEBUG ?? '').split(':').includes('track-turns');
+
+// Track-turns is disabled by default and can be enabled by an environment
+// option. We intend to change the default after verifying that having
+// the feature enabled in production does not cause memory to leak.
+const ENABLED = env?.TRACK_TURNS === 'enabled';
// We hoist these functions out of trackTurns() to discourage the
// closures from holding onto 'args' or 'func' longer than necessary,
@@ -83,7 +92,7 @@ const wrapFunction = (func, sendingError, X) => (...args) => {
* @returns {T}
*/
export const trackTurns = funcs => {
- if (typeof globalThis === 'undefined' || !globalThis.assert) {
+ if (!ENABLED || typeof globalThis === 'undefined' || !globalThis.assert) {
return funcs;
}
const { details: X } = assert;

MODIFY
packages/eventual-send/test/prepare-test-env-ava.js
packages/eventual-send/test/prepare-test-env-ava.js
+/* global process */
+
import '@endo/lockdown/commit-debug.js';
import { wrapTest } from '@endo/ses-ava';
@@ -7,3 +9,5 @@ export * from 'ava';
/** @type {typeof rawTest} */
export const test = wrapTest(rawTest);
+
+process.env.TRACK_TURNS = 'enabled';

feat(eventual-send): Feature-flag track-turns

Introduces DEBUG=track-turns and TRACK_TURNS=enabled environment flags.