I’m always struck by US Grant in this regard. Suffering of debilitating cancer of throat, but convinced by Mark Twain and others his memoirs would bring financial benefit to his family after a failed business post presidency. He completed them and died a few days later, his final mission for his family.