A code snippet of netty examples from netty.io seems have bugs -
the code snippet is:
final channelfuture f = ctx.writeandflush(time); f.addlistener(new channelfuturelistener() { public void operationcomplete(channelfuture future) { assert f == future; ctx.close(); } });
what happens if ' final channelfuture f = ctx.writeandflush(time); ' executes fast next addlistener
code not start yet. when first line of code completes, thread notifies listeners operation done, @ time, there no listener @ all! after that, new listener added no more notifications received!
code source: http://netty.io/wiki/user-guide-for-5.x.html
the channelfuture retains completion state if listener added after completion, "late" added listener called on addition.
see javadoc channelfuture.addlistener(genericfuturelistener), comment:
if future completed, specified listener notified immediately.
see impl defaultpromise. late listeners (i.e. listeners added once future complete) have own handler (notifylatelistener).
Comments
Post a Comment