Skip to content

Instantly share code, notes, and snippets.

@Jim-Lin
Last active March 5, 2016 17:08
Show Gist options
  • Save Jim-Lin/c365eb6431e3f8f2aeb0 to your computer and use it in GitHub Desktop.
Save Jim-Lin/c365eb6431e3f8f2aeb0 to your computer and use it in GitHub Desktop.
[Netty] brief talk about Non-Blocking I/O ref: http://qiita.com/SHUAI/items/bea4b8621380b642f116
// sample code:
read(file, tmp_buf, len);
write(socket, tmp_buf, len);
// sample code:
tmp_buf = mmap(file, len);
write(socket, tmp_buf, len);
// sample code:
sendfile(socket, file, len);
public class Example {
public static void main(String... args) throws Exception {
ExecResult<String> result = ExecHarness.yieldSingle(c ->
Promise.value("foo")
.transform(up -> down ->
up.connect(down.<String>onSuccess(value -> {
try {
down.success(value.toUpperCase());
} catch (Throwable e) {
down.error(e);
}
}))
)
);
assertEquals("FOO", result.getValue());
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment