Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to listen to finish of a write stream if requests were retried? #48

Open
k0pernikus opened this issue Sep 30, 2016 · 3 comments
Open

Comments

@k0pernikus
Copy link

k0pernikus commented Sep 30, 2016

I have:

    return new Promise<string>(resolve => {
        request(options)
            .pipe(fs.createWriteStream(fileName))
            .on("finish", function () {
                console.log("The file should be completely written here");
                resolve(fileName);
            });
    });

and I expected the finish to only be emitted if one of my retryable requests went through.

Instead, if there is a retry, the finish will be emitted already for the first request and resolve the promise prematurely.

I want to resolve my Promise if and only if one request was successful and the writing to the stream finished with the content. How do I achieve that?

--- Want to back this issue? **[Post a bounty on it!](https://www.bountysource.com/issues/38111507-how-to-listen-to-finish-of-a-write-stream-if-requests-were-retried?utm_campaign=plugin&utm_content=tracker%2F1861872&utm_medium=issues&utm_source=github)** We accept bounties via [Bountysource](https://www.bountysource.com/?utm_campaign=plugin&utm_content=tracker%2F1861872&utm_medium=issues&utm_source=github).
@FGRibreau
Copy link
Owner

Hello @k0pernikus,

Indeed that would be a new feature, requestretry is more oriented towards requests retry that stream retry, so that why you don't have the intended behaviour.

I will happily accept a PR with tests for this :)

@rishav-csenitjsr
Copy link

Hey, is there any update on this issue ? @k0pernikus @FGRibreau
I need to do pipe request body to a file only when we get some file in our response body.
How to achieve that ? Is there any solution with request retry ? @FGRibreau

@FGRibreau
Copy link
Owner

@k0pernikus @rishav-csenitjsr

How to achieve that ? Is there any solution with request retry ?

I don't think so, I'm open for PR along with tests that fixes that 👍

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

No branches or pull requests

3 participants