Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(391)

Side by Side Diff: lib/src/channel_manager.dart

Issue 1890003002: Fix a race condition. (Closed) Base URL: git@github.com:dart-lang/json_rpc_2.git@master
Patch Set: Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « CHANGELOG.md ('k') | pubspec.yaml » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 import 'dart:async'; 5 import 'dart:async';
6 6
7 import 'package:stream_channel/stream_channel.dart'; 7 import 'package:stream_channel/stream_channel.dart';
8 8
9 /// Wraps a [StreamChannel] and handles logic that's shared between [Server], 9 /// Wraps a [StreamChannel] and handles logic that's shared between [Server],
10 /// [Client], and [Peer]. 10 /// [Client], and [Peer].
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
49 if (_listenCalled) { 49 if (_listenCalled) {
50 throw new StateError("Can only call $_name.listen() once."); 50 throw new StateError("Can only call $_name.listen() once.");
51 } 51 }
52 _listenCalled = true; 52 _listenCalled = true;
53 53
54 _channel.stream.listen(handleInput, 54 _channel.stream.listen(handleInput,
55 onError: (error, stackTrace) { 55 onError: (error, stackTrace) {
56 _doneCompleter.completeError(error, stackTrace); 56 _doneCompleter.completeError(error, stackTrace);
57 _channel.sink.close(); 57 _channel.sink.close();
58 }, 58 },
59 onDone: _doneCompleter.complete, 59 onDone: () {
60 if (!_doneCompleter.isCompleted) _doneCompleter.complete();
61 },
60 cancelOnError: true); 62 cancelOnError: true);
61 63
62 return done; 64 return done;
63 } 65 }
64 66
65 /// Emit [event]. 67 /// Emit [event].
66 void add(event) { 68 void add(event) {
67 if (isClosed && !_closeCalled) return; 69 if (isClosed && !_closeCalled) return;
68 _channel.sink.add(event); 70 _channel.sink.add(event);
69 } 71 }
70 72
71 /// Closes the channel. 73 /// Closes the channel.
72 Future close() { 74 Future close() {
73 _closeCalled = true; 75 _closeCalled = true;
74 if (!_doneCompleter.isCompleted) { 76 if (!_doneCompleter.isCompleted) {
75 _doneCompleter.complete(_channel.sink.close()); 77 _doneCompleter.complete(_channel.sink.close());
76 } 78 }
77 return done; 79 return done;
78 } 80 }
79 } 81 }
OLDNEW
« no previous file with comments | « CHANGELOG.md ('k') | pubspec.yaml » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698