Skip to content

Commit 3223660

Browse files
committed
---
yaml --- r: 82469 b: refs/heads/auto c: 48d5b4b h: refs/heads/master i: 82467: 801a0cf v: v3
1 parent 1dc13da commit 3223660

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ refs/heads/try3: 9387340aab40a73e8424c48fd42f0c521a4875c0
1313
refs/tags/release-0.3.1: 495bae036dfe5ec6ceafd3312b4dca48741e845b
1414
refs/tags/release-0.4: e828ea2080499553b97dfe33b3f4d472b4562ad7
1515
refs/tags/release-0.5: 7e3bcfbf21278251ee936ad53e92e9b719702d73
16-
refs/heads/auto: ff85389344d6fe4a318559b66b97c24b8fddf1e4
16+
refs/heads/auto: 48d5b4b8e163a4eb4a8290bfed6786b333f49117
1717
refs/heads/servo: af82457af293e2a842ba6b7759b70288da276167
1818
refs/tags/release-0.6: b4ebcfa1812664df5e142f0134a5faea3918544c
1919
refs/tags/0.1: b19db808c2793fe2976759b85a355c3ad8c8b336

branches/auto/src/libextra/future.rs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,23 @@ impl<A:Send> Future<A> {
139139

140140
Future::from_port(port)
141141
}
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+
}
142159
}
143160

144161
#[cfg(test)]
@@ -193,6 +210,12 @@ mod test {
193210
assert_eq!(f.get(), ~"bale");
194211
}
195212
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+
196219
#[test]
197220
#[should_fail]
198221
fn test_futurefail() {

0 commit comments

Comments
 (0)