'Override parent write_message with a version that consistently returns Future across Tornado versions'

@gen.coroutine
def write_message(self, message, binary=False, locked=True):

    def write_message_unlocked():
        future = super(WSHandler, self).write_message(message, binary)
        if (future is None):
            future = Future()
            future.set_result(None)
        raise gen.Return(future)
    if locked:
        with (yield self.write_lock.acquire()):
            write_message_unlocked()
    else:
        write_message_unlocked()
