OLD | NEW |
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, 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 library scheduled_test.scheduled_server; | 5 library scheduled_test.scheduled_server; |
6 | 6 |
7 import 'dart:async'; | 7 import 'dart:async'; |
8 import 'dart:collection'; | 8 import 'dart:collection'; |
9 import 'dart:io'; | 9 import 'dart:io'; |
10 | 10 |
(...skipping 30 matching lines...) Expand all Loading... |
41 /// 127.0.0.1. [description] is used to refer to the server in debugging | 41 /// 127.0.0.1. [description] is used to refer to the server in debugging |
42 /// messages. | 42 /// messages. |
43 factory ScheduledServer([String description]) { | 43 factory ScheduledServer([String description]) { |
44 var id = _count++; | 44 var id = _count++; |
45 if (description == null) description = 'scheduled server $id'; | 45 if (description == null) description = 'scheduled server $id'; |
46 | 46 |
47 var scheduledServer; | 47 var scheduledServer; |
48 scheduledServer = new ScheduledServer._(schedule(() { | 48 scheduledServer = new ScheduledServer._(schedule(() { |
49 return SafeHttpServer.bind("127.0.0.1", 0).then((server) { | 49 return SafeHttpServer.bind("127.0.0.1", 0).then((server) { |
50 server.listen(scheduledServer._handleRequest, | 50 server.listen(scheduledServer._handleRequest, |
51 onError: (e) => currentSchedule.signalError(e)); | 51 onError: currentSchedule.signalError); |
52 currentSchedule.onComplete.schedule(server.close); | 52 currentSchedule.onComplete.schedule(server.close); |
53 return server; | 53 return server; |
54 }); | 54 }); |
55 }, "starting '$description'"), description); | 55 }, "starting '$description'"), description); |
56 return scheduledServer; | 56 return scheduledServer; |
57 } | 57 } |
58 | 58 |
59 /// The port on which the server is listening. | 59 /// The port on which the server is listening. |
60 Future<int> get port => _server.then((s) => s.port); | 60 Future<int> get port => _server.then((s) => s.port); |
61 | 61 |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
95 "when no more requests were expected."); | 95 "when no more requests were expected."); |
96 } | 96 } |
97 return _handlers.removeFirst().fn(request); | 97 return _handlers.removeFirst().fn(request); |
98 }).catchError((e) { | 98 }).catchError((e) { |
99 // Close the server so that we don't leave a dangling request. | 99 // Close the server so that we don't leave a dangling request. |
100 _server.then((s) => s.close()); | 100 _server.then((s) => s.close()); |
101 throw e; | 101 throw e; |
102 }), 'receiving ${request.method} ${request.uri}'); | 102 }), 'receiving ${request.method} ${request.uri}'); |
103 } | 103 } |
104 } | 104 } |
OLD | NEW |