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

update to work with ws instead of websocket-server #9

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

neonstalwart
Copy link
Member

No description provided.

@neonstalwart
Copy link
Member Author

I don't think streaming is working like it should. i want to try something tomorrow since ws sockets support streaming.

it would be good if this could be made to stream from forEach but it
seems that forEach doesn't accept backpressure.
@neonstalwart
Copy link
Member Author

@kriszyp is it possible to apply backpressure to forEach?

using the following code

when(jsgiApp(request), function(response){
    when(response.body, function(body){
        console.log('reading body...');
        when(body.forEach(function (data) {
            var dfd = require('./promise').defer();
            console.log('sending data', data);
            socket.send(data);
            setTimeout(function () {
                console.log('resolving', data);
                dfd.resolve();
            }, 300);
            return dfd.promise;
        }), function () {
            console.log('done');
        });
    });
});

i see this output

reading body...
sending data {}&&
sending data [
sending data {"status":403,"headers":{"vary":"Accept","content-type":"message/json; charset=UTF-8"},"body":{}}
sending data ]
done
resolving {}&&
resolving [
resolving {"status":403,"headers":{"vary":"Accept","content-type":"message/json; charset=UTF-8"},"body":{}}
resolving ]

i was hoping that i could return a promise from forEach and cause the next iteration to wait on the resolution of that promise. is there anything like that?

@neonstalwart
Copy link
Member Author

if there's no way to apply backpressure then this is probably as good as it gets so feel free to merge if you're ok with it.

@kriszyp
Copy link
Member

kriszyp commented Sep 29, 2014

Merged the commits, will take a look at back-pressure later.

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

Successfully merging this pull request may close these issues.

2 participants