Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -113,3 +113,7 @@ const streamContext = createResumableStreamContext({
- When a second resumable stream is invoked for a given `streamId`, it publishes a messages to alert the producer that it would like to receive the stream.
- The second consumer now expects messages of stream content via the pubsub.
- The producer receives the request, and starts publishing the buffered messages and then publishes additional chunks of the stream.

## Debugging

Set the `DEBUG` environment variable to `resumable-stream:*` to see debug logs.
15 changes: 14 additions & 1 deletion src/runtime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -331,10 +331,23 @@ function incrOrDone(publisher: Publisher, key: string): Promise<typeof DONE_VALU
});
}

// Check if resumable-stream namespace is enabled
// Supports: DEBUG=*, DEBUG=resumable-stream:*, DEBUG=*,other-namespace, etc.
// note, this duplicates logic from the `debug` package
// which we are not adding as a dependency for security reasons.
function isDebug() {
return process.env.DEBUG;
const debug = process.env.DEBUG;
if (!debug) return false;

const namespaces = debug.split(',').map(ns => ns.trim());
return namespaces.some(ns =>
ns === '*' ||
ns === 'resumable-stream' ||
ns.startsWith('resumable-stream:')
);
}


function debugLog(...messages: unknown[]) {
if (isDebug()) {
console.log(...messages);
Expand Down