Skip to content

I don't know why it not work if I not call stream.write('') with unjs/h3 server #7

Description

@Maxttier

Work without call of stream.write if run with bun dev not work if run with bun -b dev. To work need to add stream.write().

const sse = require('https://github.com/EventSource/node-ssestream/blob/master/index.ts');
const rxjs_1 = require("rxjs");
const operators_1 = require("rxjs/operators");



const stream = new sse.SseStream(request);
stream.pipe(response, options);

// stream.write('');

const subscription = result
    .pipe((0, operators_1.map)((message) => {
    if ((0, shared_utils_1.isObject)(message)) {
        return message;
    }
    return { data: message };
}), (0, operators_1.concatMap)(message => 
    new Promise(resolve => stream.writeMessage(
        message, 
        () => resolve()))), 
        (0, operators_1.catchError
    )(err => {
    const data = err instanceof Error ? err.message : err;
    stream.writeMessage({ type: 'error', data }, writeError => {
        if (writeError) {
            this.logger.error(writeError);
        }
    });
    return rxjs_1.EMPTY;
}))
    .subscribe({
    complete: () => {
        response.end();
    },
});

request.on('close', () => {
    subscription.unsubscribe();
    if (!stream.writableEnded) {
        stream.end();
    }
});

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions