Observable<AsyncFile> obs = Vertx.currentContext().<AsyncFile>executeBlockingObservable(f -> {
AsyncFile aFile = vertx.fileSystem().openBlocking("aFile.txt", new OpenOptions());
f.complete(aFile);
});
obs.subscribe(file -> {
ctx.response().putHeader("Content-Length", "19");
Pump p = Pump.pump(file, ctx.response(), 19);
p.start();
file.endHandler(e->{
logger.info("end file");
ctx.response().end();
});
}, error -> {
logger.error(error.getMessage(), error);
});
vertx.fileSystem().open("aFile.txt", new OpenOptions(), ar -> {
if (ar.succeeded()) {
AsyncFile file = ar.result();
ctx.response().putHeader("Content-Length", "19");
Pump p = Pump.pump(file, ctx.response(), 19);
p.start();
file.endHandler(e->{
logger.info("end file");
ctx.response().end();
});
} else {
Throwable error = ar.cause();
logger.error(error.getMessage(), error);
}
});
});
--
You received this message because you are subscribed to the Google Groups "vert.x" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vertx+un...@googlegroups.com.
Visit this group at https://groups.google.com/group/vertx.
To view this discussion on the web, visit https://groups.google.com/d/msgid/vertx/789c20c5-f751-44e5-9a24-ca4dfcccf437%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
thanks Julien
Would it be correct to say .end should always be called on writeStream, even when using Pump?
Also I'm not quiet sure when to use executeBlocking.
In my main project I use a vertx http client a lot. I wrapped all these requests in executeBlocking methods as I was worried if they were slow or delayed they would block the event loop.... but I think this may have been an incorrect assumption?
Are there any good reading materials about how and when the event loop gets blocked?
I have seen lots of warnings about the "golden rule" of not blocking the event loop, but not a good explanation of what will cause a block or how to identify code which should be in executeBlocking.
Thanks for the help,
Patrick
To unsubscribe from this group and stop receiving emails from it, send an email to vertx+unsubscribe@googlegroups.com.
Visit this group at https://groups.google.com/group/vertx.
To view this discussion on the web, visit https://groups.google.com/d/msgid/vertx/789c20c5-f751-44e5-9a24-ca4dfcccf437%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
--
You received this message because you are subscribed to a topic in the Google Groups "vert.x" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/vertx/9Vj0zkKHOPA/unsubscribe.
To unsubscribe from this group and all its topics, send an email to vertx+unsubscribe@googlegroups.com.
Visit this group at https://groups.google.com/group/vertx.
To view this discussion on the web, visit https://groups.google.com/d/msgid/vertx/A997232C-CCF9-40B5-9ABF-360F3EE4F184%40julienviet.com.
To unsubscribe from this group and stop receiving emails from it, send an email to vertx+un...@googlegroups.com.
Visit this group at https://groups.google.com/group/vertx.
To view this discussion on the web, visit https://groups.google.com/d/msgid/vertx/789c20c5-f751-44e5-9a24-ca4dfcccf437%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
--
You received this message because you are subscribed to a topic in the Google Groups "vert.x" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/vertx/9Vj0zkKHOPA/unsubscribe.
To unsubscribe from this group and all its topics, send an email to vertx+un...@googlegroups.com.
thanks Alexander
To unsubscribe from this group and all its topics, send an email to vertx+unsubscribe@googlegroups.com.
Visit this group at https://groups.google.com/group/vertx.
To view this discussion on the web, visit https://groups.google.com/d/msgid/vertx/7cfe4468-f945-46be-96d4-9d0ce7cce656%40googlegroups.com.