"The Dream," the final chapter of Julian Barnes' novel in stories The History of the World in 10 1/2 Chapters (1989), takes place in heaven. It begins with the unnamed narrator of this chapter declaring that "I dreamt that I woke up. It's the oldest dream of all, and I've just had it." Heaven is the place where you get everything you want. To the narrator's delight, he has unlimited access to the best food, he can play golf every day, and have sex with beautiful women every night. As one of heaven's employees (whether they're angels, or former people, or something else entirely is never clarified) states, "'the principle of heaven [is] that you get what you want, what you expect.'" There's no hell, just "something we call Hell. But it's more like a theme park. You know, skeletons popping out and frightening you..." The only positive thing on earth that's absent in heaven is dreaming. But as perfect and wonderful as heaven is, "there aren't an infinite number of possibilities." The narrator eventually gets so good at golf that he hits a hole in one on every shot. Eventually, he completely masters every sport. Asking one of the employees what will happen, eventually, and what heaven was like in the old days, he discovers that "If you want to die off, you do. You just have to want it long enough and that's it, it happens" and "everyone takes the option [to die], sooner or later." Eventually, the narrator decides that the time has come, so he goes to bed, planning to decide on death once he wakes up. The next and final line of the story is "I dreamt that I woke up. It's the oldest dream of all, and I've just had it." While it's possible to read this line as a simple restatement of the opening, the fact that this line takes place immediately after the narrator goes to bed and decides to start dying, and the fact that Barnes specifically established that people don't dream in heaven, suggests that the story is cyclical. Once you get so tired of eternal paradise that you want to die, you start over. The idea of a cyclical afterlife is not rare in fiction. But it usually describes hell.
The earliest work I know of to present a cyclical afterlife is Flann O'Brien's The Third Policeman (written in 1939-40, though not published for a couple decades), in which an unnamed narrator finds himself awaiting execution in an increasingly surreal environment until, at the end, he discovers that he has been dead throughout, and the sequence of events that unfolded, and which he has already begun to forget, will repeat as a punishment for his sins. A sort of Dante in Wonderland. I can think of a few other examples off the top of my head. "Judgment Night," an early Twilight Zone episode, features a German waking up on a British cruise liner during WWII, not knowing how he got there or why he is certain the ship is going to be sunk. It turns out he was a Nazi submarine captain who ordered the passenger ship torpedoed, and now spends eternity living and reliving the suffering he caused. Stephen King and Neil Gaiman have both written stories that deal with a cyclical hell ("That Feeling You Can Only Say What It Is in French" and "Other People," respectively, although I personally think the latter may be purgatorial rather than infernal). In Joshua Fialkov's comic series, "The Life After," suicides relive the same day for eternity.
So why, if endless repetition is consistently presented as divine punishment, is it heaven in Barnes's novel? Perhaps the answer lies in how we construe heaven. Putting aside religious literature* for the moment, how is heaven, as an afterlife, portrayed in modern fiction? Well, when it is portrayed, it often ends up as a kind of "happily ever after" scenario (as in, e.g., the Albert Brooks movie Defending Your Life (1991)). Other times, it serves as a useful plot element, usually as a way to let the dead speak (e.g., Alice Sebold's The Lovely Bones (2002) or Vonnegut's God Bless You, Dr. Kevorkian, a series of radioplays where Vonnegut interviews dead historical figures). The point I'm getting at, is that the experience of an eternal life in heaven is rarely dealt with in modern fiction. What would something like that look like? One example that sticks in my mind comes from Jhonen Vasquez's graphic novel, Johnny the Homicidal Maniac (1997) in which the titular character, touring the afterlife, visits heaven, only to find millions of people sitting quietly and staring into space. When he asks what the deal is, he's told that all the people there are perfectly content. And so they sit there. Eternally. (Well, except for a brief spate of hyper-violence, anyway).
If this endless, passive contentment doesn't sound appealing, what type of eternity could we have? We could consider an eternal soul that is stripped of our human desires, that becomes something fundamentally different from what we were when we were alive, but then you can't say that it is "you" who are in eternal paradise, anymore than it is "you" who would be absorbed into the soil after burial. What Barnes has realized is that perhaps eternity is inherently hostile to human consciousness. As Barnes' narrator concludes, "Heaven's a very good idea, it's a perfect idea you could say, but not for us. Not given the way we are." But the alternative is non-existence. The underlying unease in this chapter can be summed up by one question: What if this is the best possible scenario?
*By religious literature, I mean works that are specifically aimed at a religious audience and that claim some spiritual value, whether this be a Lloyd C. Douglas biblical epic or Left Behind. Heaven, for these writers, is a oneness with god, and is a theological issue, not a narrative one.