Fix state error with keep alive (#24)

diff --git a/CHANGELOG.md b/CHANGELOG.md
index 5135fb4..f320635 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,3 +1,8 @@
+## 3.2.2
+
+- Fix an issue where `keepAlive` may cause state errors when attempting to
+  send messages on a closed stream.
+
 ## 3.2.1
 
 - Fix an issue where `keepAlive` would only allow a single reconnection.
diff --git a/lib/src/server/sse_handler.dart b/lib/src/server/sse_handler.dart
index 1749f46..ed4cb9e 100644
--- a/lib/src/server/sse_handler.dart
+++ b/lib/src/server/sse_handler.dart
@@ -68,6 +68,11 @@
       // Peek the data so we don't remove it from the stream if we're unable to
       // send it.
       final data = await outgoingStreamQueue.peek;
+
+      // Ignore outgoing messages since the connection may have closed while
+      // waiting for the keep alive.
+      if (_closedCompleter.isCompleted) break;
+
       try {
         // JSON encode the message to escape new lines.
         _sink.add('data: ${json.encode(data)}\n');
diff --git a/pubspec.yaml b/pubspec.yaml
index 1381d61..8e3ab44 100644
--- a/pubspec.yaml
+++ b/pubspec.yaml
@@ -1,5 +1,5 @@
 name: sse
-version: 3.2.1
+version: 3.2.2
 homepage: https://github.com/dart-lang/sse
 description: >-
   Provides client and server functionality for setting up bi-directional