The solution I have found is to set an alarm clock for going to bed. This works differently than the alarm clock I use for waking up because I don’t set the alarm to ring at the exact time that I’m supposed to close my eyes, rather I set the alarm 30 minutes earlier so that I have enough time to finish what I have started.