Skip to content

Commit e98a444

Browse files
committed
---
yaml --- r: 83263 b: refs/heads/try c: 48d5b4b h: refs/heads/master i: 83261: 8995d63 83259: 6bdaa0d 83255: 83c1466 83247: 6f1770a 83231: f8a293d 83199: 52dccb7 v: v3
1 parent 83a6a0e commit e98a444

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
@@ -2,7 +2,7 @@
22
refs/heads/master: 0e4d1fc8cae42e15e00f71d9f439b01bb25a86ae
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
44
refs/heads/snap-stage3: 6c08cc2db4f98e9f07ae7d50338396c4123c2f0a
5-
refs/heads/try: ff85389344d6fe4a318559b66b97c24b8fddf1e4
5+
refs/heads/try: 48d5b4b8e163a4eb4a8290bfed6786b333f49117
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
88
refs/heads/try2: 147ecfdd8221e4a4d4e090486829a06da1e0ca3c

branches/try/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)