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

Side by Side Diff: pkg/shelf/lib/src/pipeline.dart

Issue 238813003: pkg/shelf: rename Stack to Pipeline (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file 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 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 shelf.stack; 5 library shelf.pipeline;
6 6
7 import 'handler.dart'; 7 import 'handler.dart';
8 import 'middleware.dart'; 8 import 'middleware.dart';
9 9
10 /// A helper that makes it easy to compose a set of [Middleware] and a 10 /// A helper that makes it easy to compose a set of [Middleware] and a
11 /// [Handler]. 11 /// [Handler].
12 /// 12 ///
13 /// var handler = const Stack() 13 /// var handler = const Pipeline()
14 /// .addMiddleware(loggingMiddleware) 14 /// .addMiddleware(loggingMiddleware)
15 /// .addMiddleware(cachingMiddleware) 15 /// .addMiddleware(cachingMiddleware)
16 /// .addHandler(application); 16 /// .addHandler(application);
17 class Stack { 17 class Pipeline {
18 final Stack _parent; 18 final Pipeline _parent;
19 final Middleware _middleware; 19 final Middleware _middleware;
20 20
21 const Stack() 21 const Pipeline()
22 : _middleware = null, 22 : _middleware = null,
23 _parent = null; 23 _parent = null;
24 24
25 Stack._(this._middleware, this._parent); 25 Pipeline._(this._middleware, this._parent);
26 26
27 /// Returns a new [Stack] with [middleware] added to the existing set of 27 /// Returns a new [Pipeline] with [middleware] added to the existing set of
28 /// [Middleware]. 28 /// [Middleware].
29 /// 29 ///
30 /// [middleware] will be the last [Middleware] to process a request and 30 /// [middleware] will be the last [Middleware] to process a request and
31 /// the first to process a response. 31 /// the first to process a response.
32 Stack addMiddleware(Middleware middleware) => 32 Pipeline addMiddleware(Middleware middleware) =>
33 new Stack._(middleware, this); 33 new Pipeline._(middleware, this);
34 34
35 /// Returns a new [Handler] with [handler] as the final processor of a 35 /// Returns a new [Handler] with [handler] as the final processor of a
36 /// [Request] if all of the middleware in the stack have passed the request 36 /// [Request] if all of the middleware in the pipeline have passed the request
37 /// through. 37 /// through.
38 Handler addHandler(Handler handler) { 38 Handler addHandler(Handler handler) {
39 if (_middleware == null) return handler; 39 if (_middleware == null) return handler;
40 return _parent.addHandler(_middleware(handler)); 40 return _parent.addHandler(_middleware(handler));
41 } 41 }
42 42
43 /// Exposes this stack of [Middleware] as a single middleware instance. 43 /// Exposes this pipeline of [Middleware] as a single middleware instance.
44 Middleware get middleware => addHandler; 44 Middleware get middleware => addHandler;
45 } 45 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698