Dolphins and whales often sleep with one eye open in order to avoid being eaten by sharks. The ability to stay partially conscious also allows them to continue to get air while sleeping.
How dolphins handle this is to put one half of their brain to sleep, while the other half is still conscious and functioning. They then alternate which side is sleeping periodically. They stay in this state for approximately eight hours a day. Doing this allows them to be conscious enough to control their breathing and periodically swim to the surface and get air, while still giving their brain the rest it needs.
The dolphin will shut down half of its brain, and the corresponding eye will also close. For example when the left side of the brain is closed the left eye closes. Another advantage of this form of sleep is that the dolphin can keep up with physiological processes, such as muscle movement, that help the warm blooded mammal maintain body heat required to survive in the frigid ocean.
There are other animals that also sleep in this way, Mallard ducks for example sleep in rows. The ducks at the end of the row keep one eye open and keep an eye out for any predators. The ducks in the middle of the row would sleep with both eyes closed.
Even with half of their brain asleep, the ducks were able to respond to the movement of a predator within a fifth of a second.