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

Side by Side Diff: pkg/http_multi_server/lib/src/utils.dart

Issue 317803003: Add a LICENSE file to pkg/http_multi_server. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 6 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 | Annotate | Revision Log
« no previous file with comments | « pkg/http_multi_server/lib/http_multi_server.dart ('k') | pkg/http_multi_server/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
(Empty)
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file
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.
4
5 library http_multi_server.utils;
6
7 import 'dart:async';
8 import 'dart:io';
9
10 /// Merges all streams in [streams] into a single stream that emits all of their
11 /// values.
12 ///
13 /// The returned stream will be closed only when every stream in [streams] is
14 /// closed.
15 Stream mergeStreams(Iterable<Stream> streams) {
16 var subscriptions = new Set();
17 var controller;
18 controller = new StreamController(onListen: () {
19 for (var stream in streams) {
20 var subscription;
21 subscription = stream.listen(controller.add,
22 onError: controller.addError,
23 onDone: () {
24 subscriptions.remove(subscription);
25 if (subscriptions.isEmpty) controller.close();
26 });
27 subscriptions.add(subscription);
28 }
29 }, onCancel: () {
30 for (var subscription in subscriptions) {
31 subscription.cancel();
32 }
33 }, onPause: () {
34 for (var subscription in subscriptions) {
35 subscription.pause();
36 }
37 }, onResume: () {
38 for (var subscription in subscriptions) {
39 subscription.resume();
40 }
41 }, sync: true);
42
43 return controller.stream;
44 }
45
46 /// A cache for [supportsIpV6].
47 bool _supportsIpV6;
48
49 /// Returns whether this computer supports binding to IPv6 addresses.
50 Future<bool> get supportsIpV6 {
51 if (_supportsIpV6 != null) return new Future.value(_supportsIpV6);
52
53 return ServerSocket.bind(InternetAddress.LOOPBACK_IP_V6, 0).then((socket) {
54 _supportsIpV6 = true;
55 socket.close();
56 return true;
57 }).catchError((error) {
58 if (error is! SocketException) throw error;
59 _supportsIpV6 = false;
60 return false;
61 });
62 }
OLDNEW
« no previous file with comments | « pkg/http_multi_server/lib/http_multi_server.dart ('k') | pkg/http_multi_server/pubspec.yaml » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698