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

Side by Side Diff: samples/chat/chat_server_lib.dart

Issue 8992007: Make the repeating argument to timers optional. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Addressed comments. Created 9 years 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 | « samples/chat/chat_server.dart ('k') | samples/chat/http_impl.dart » ('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) 2011, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2011, 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("chat_server"); 5 #library("chat_server");
6 #import("http.dart"); 6 #import("http.dart");
7 #import("../../client/json/dart_json.dart"); 7 #import("../../client/json/dart_json.dart");
8 8
9 typedef void RequestHandler(HTTPRequest request, HTTPResponse response); 9 typedef void RequestHandler(HTTPRequest request, HTTPResponse response);
10 10
(...skipping 573 matching lines...) Expand 10 before | Expand all | Expand 10 after
584 584
585 void main() { 585 void main() {
586 _logRequests = false; 586 _logRequests = false;
587 _topic = new Topic(); 587 _topic = new Topic();
588 _serverStart = new Date.now(); 588 _serverStart = new Date.now();
589 _messageCount = 0; 589 _messageCount = 0;
590 _messageRate = new Rate(); 590 _messageRate = new Rate();
591 591
592 // Start a timer for cleanup events. 592 // Start a timer for cleanup events.
593 _cleanupTimer = 593 _cleanupTimer =
594 new Timer((timer) => _topic._handleTimer(timer), 10000, true); 594 new Timer.repeating((timer) => _topic._handleTimer(timer), 10000);
595 595
596 // Start timer for periodic logging. 596 // Start timer for periodic logging.
597 void _handleLogging(Timer timer) { 597 void _handleLogging(Timer timer) {
598 if (_logging) { 598 if (_logging) {
599 print((_messageRate.rate).toString() + 599 print((_messageRate.rate).toString() +
600 " messages/s (total " + 600 " messages/s (total " +
601 _messageCount + 601 _messageCount +
602 " messages)"); 602 " messages)");
603 } 603 }
604 } 604 }
605 605
606 this.port.receive( 606 this.port.receive(
607 void _(var message, SendPort replyTo) { 607 void _(var message, SendPort replyTo) {
608 if (message.isStart) { 608 if (message.isStart) {
609 _host = message.host; 609 _host = message.host;
610 _port = message.port; 610 _port = message.port;
611 _logging = message.logging; 611 _logging = message.logging;
612 replyTo.send(new ChatServerStatus.starting(), null); 612 replyTo.send(new ChatServerStatus.starting(), null);
613 _server = new HTTPServer(); 613 _server = new HTTPServer();
614 try { 614 try {
615 _server.listen( 615 _server.listen(
616 _host, 616 _host,
617 _port, 617 _port,
618 (HTTPRequest req, HTTPResponse rsp) => 618 (HTTPRequest req, HTTPResponse rsp) =>
619 _requestReceivedHandler(req, rsp), 619 _requestReceivedHandler(req, rsp),
620 backlog: message.backlog); 620 backlog: message.backlog);
621 replyTo.send(new ChatServerStatus.started(_server.port), null); 621 replyTo.send(new ChatServerStatus.started(_server.port), null);
622 _loggingTimer = new Timer(_handleLogging, 1000, true); 622 _loggingTimer = new Timer.repeating(_handleLogging, 1000);
623 } catch (var e) { 623 } catch (var e) {
624 replyTo.send(new ChatServerStatus.error(e.toString()), null); 624 replyTo.send(new ChatServerStatus.error(e.toString()), null);
625 } 625 }
626 } else if (message.isStop) { 626 } else if (message.isStop) {
627 replyTo.send(new ChatServerStatus.stopping(), null); 627 replyTo.send(new ChatServerStatus.stopping(), null);
628 stop(); 628 stop();
629 replyTo.send(new ChatServerStatus.stopped(), null); 629 replyTo.send(new ChatServerStatus.stopped(), null);
630 } 630 }
631 }); 631 });
632 } 632 }
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
738 } 738 }
739 } 739 }
740 740
741 int _timeRange; 741 int _timeRange;
742 List<int> _buckets; 742 List<int> _buckets;
743 int _currentBucket; 743 int _currentBucket;
744 int _currentBucketTime; 744 int _currentBucketTime;
745 num _bucketTimeRange; 745 num _bucketTimeRange;
746 int _sum; 746 int _sum;
747 } 747 }
OLDNEW
« no previous file with comments | « samples/chat/chat_server.dart ('k') | samples/chat/http_impl.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698