Async client wait till write completes


#1

I am using an async client to write some data. However, after executing some write commands and immediately closing AsyncClient via close() method I’m catching an exception in WriteListener saying:

com.aerospike.client.AerospikeException: java.nio.channels.ClosedByInterruptException
        at com.aerospike.client.async.SelectorManager.processKey(SelectorManager.java:185)
        at com.aerospike.client.async.SelectorManager.runCommands(SelectorManager.java:107)
        at com.aerospike.client.async.SelectorManager.run(SelectorManager.java:68)
Caused by: java.nio.channels.ClosedByInterruptException
        at java.nio.channels.spi.AbstractInterruptibleChannel.end(AbstractInterruptibleChannel.java:202)
        at sun.nio.ch.SocketChannelImpl.write(SocketChannelImpl.java:478)
        at com.aerospike.client.async.AsyncConnection.write(AsyncConnection.java:108)
        at com.aerospike.client.async.AsyncCommand.write(AsyncCommand.java:142)
        at com.aerospike.client.async.SelectorManager.processKey(SelectorManager.java:171)
        ... 2 more

The data, supposed to be written, is missing. How should i handle WriteListener’s result to wait write command’s completion before I try to close the client?