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 @@ -13,7 +13,7 @@ refs/heads/try3: 9387340aab40a73e8424c48fd42f0c521a4875c0
13
13
refs/tags/release-0.3.1: 495bae036dfe5ec6ceafd3312b4dca48741e845b
14
14
refs/tags/release-0.4: e828ea2080499553b97dfe33b3f4d472b4562ad7
15
15
refs/tags/release-0.5: 7e3bcfbf21278251ee936ad53e92e9b719702d73
16
- refs/heads/auto: ff85389344d6fe4a318559b66b97c24b8fddf1e4
16
+ refs/heads/auto: 48d5b4b8e163a4eb4a8290bfed6786b333f49117
17
17
refs/heads/servo: af82457af293e2a842ba6b7759b70288da276167
18
18
refs/tags/release-0.6: b4ebcfa1812664df5e142f0134a5faea3918544c
19
19
refs/tags/0.1: b19db808c2793fe2976759b85a355c3ad8c8b336
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