File tree Expand file tree Collapse file tree 2 files changed +24
-1
lines changed Expand file tree Collapse file tree 2 files changed +24
-1
lines changed Original file line number Diff line number Diff line change 2
2
refs/heads/master: 0e4d1fc8cae42e15e00f71d9f439b01bb25a86ae
3
3
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
4
4
refs/heads/snap-stage3: 6c08cc2db4f98e9f07ae7d50338396c4123c2f0a
5
- refs/heads/try: ff85389344d6fe4a318559b66b97c24b8fddf1e4
5
+ refs/heads/try: 48d5b4b8e163a4eb4a8290bfed6786b333f49117
6
6
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
7
7
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
8
8
refs/heads/try2: 147ecfdd8221e4a4d4e090486829a06da1e0ca3c
Original file line number Diff line number Diff line change @@ -139,6 +139,23 @@ impl<A:Send> Future<A> {
139
139
140
140
Future :: from_port ( port)
141
141
}
142
+
143
+ pub fn spawn_with < B : Send > ( v : B , blk : ~fn ( B ) -> A ) -> Future < A > {
144
+ /*!
145
+ * Create a future from a unique closure taking one argument.
146
+ *
147
+ * The closure and its argument will be moved into a new task. The
148
+ * closure will be run and its result used as the value of the future.
149
+ */
150
+
151
+ let ( port, chan) = oneshot ( ) ;
152
+
153
+ do task:: spawn_with ( ( v, chan) ) |( v, chan) | {
154
+ chan. send ( blk ( v) ) ;
155
+ }
156
+
157
+ Future :: from_port ( port)
158
+ }
142
159
}
143
160
144
161
#[ cfg( test) ]
@@ -193,6 +210,12 @@ mod test {
193
210
assert_eq!(f.get(), ~" bale");
194
211
}
195
212
213
+ #[test]
214
+ fn test_spawn_with() {
215
+ let mut f = Future::spawn_with(~" gale", |s| { s });
216
+ assert_eq!(f.get(), ~" gale");
217
+ }
218
+
196
219
#[test]
197
220
#[should_fail]
198
221
fn test_futurefail() {
You can’t perform that action at this time.
0 commit comments