# Lost event stream \[solved\]

**URL:** <https://community.particle.io/t/lost-event-stream-solved/9304>\
**Category:** Troubleshooting\
**Created:** [January 12, 2015, 11:16am UTC](https://community.particle.io/t/lost-event-stream-solved/9304 "2015-01-12T11:16:00Z")\
**Posts on this page:** 1\
**Showing post:** 4

<div class="post-metadata">

**Author:** ![Dave](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/dave/32/181_2.png) [@Dave](https://community.particle.io/u/Dave)\
**Post date:** [January 14, 2015, 4:20pm UTC](https://community.particle.io/t/lost-event-stream-solved/9304/4 "2015-01-14T16:20:04Z")

</div>

Hey All,

While it’s not unexpected that a SSE stream will end at sometime, they do happen a little more frequently than I’d like. Here’s some example code you can write with SparkJS to automatically resume a stream if it stops:

```auto
//example code to keep SSE stream alive

 var openStream = function() {

    //Get your event stream
    var req = spark.getEventStream(false, 'mine', function(data) {
      console.log("Event: " + JSON.stringify(data));
    });

    req.on('end', function() {
        console.log("ended! re-opening in 3 seconds...");
        setTimeout(openStream, 3 * 1000);
    });
};

spark.on('login', function() {
    openStream();
});

```

Thanks!  
David

---

_[View the full topic](https://community.particle.io/t/lost-event-stream-solved/9304)._
