Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
R
rsvp.js
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Boris Kocherov
rsvp.js
Commits
34a4233b
Commit
34a4233b
authored
Sep 27, 2013
by
Tristan Cavelier
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add notifier to `all` and `any`
parent
361f17d8
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
85 additions
and
3 deletions
+85
-3
lib/rsvp/all.js
lib/rsvp/all.js
+8
-2
test/tests/extension_test.js
test/tests/extension_test.js
+77
-1
No files found.
lib/rsvp/all.js
View file @
34a4233b
...
...
@@ -18,7 +18,7 @@ function promiseAtLeast(expected_count, promises) {
}
}
return
new
Promise
(
function
(
resolve
,
reject
)
{
return
new
Promise
(
function
(
resolve
,
reject
,
notify
)
{
var
results
=
[],
remaining
=
promises
.
length
,
promise
,
remaining_count
=
promises
.
length
-
expected_count
;
...
...
@@ -48,11 +48,17 @@ function promiseAtLeast(expected_count, promises) {
}
}
function
notifier
(
index
)
{
return
function
(
value
)
{
notify
({
"
index
"
:
index
,
"
value
"
:
value
});
};
}
for
(
var
i
=
0
;
i
<
promises
.
length
;
i
++
)
{
promise
=
promises
[
i
];
if
(
promise
&&
typeof
promise
.
then
===
'
function
'
)
{
promise
.
then
(
resolver
(
i
),
reject
);
promise
.
then
(
resolver
(
i
),
reject
,
notifier
(
i
)
);
}
else
{
resolveAll
(
i
,
promise
);
}
...
...
test/tests/extension_test.js
View file @
34a4233b
...
...
@@ -781,6 +781,44 @@ describe("RSVP extensions", function() {
done
();
},
20
);
});
specify
(
'
notifies promises progress
'
,
function
(
done
)
{
var
firstResolver
,
secondResolver
,
count
=
0
,
expected
=
{};
var
first
=
new
RSVP
.
Promise
(
function
(
resolve
,
reject
,
notify
)
{
firstResolver
=
{
resolve
:
resolve
,
reject
:
reject
,
notify
:
notify
};
});
var
second
=
new
RSVP
.
Promise
(
function
(
resolve
,
reject
,
notify
)
{
secondResolver
=
{
resolve
:
resolve
,
reject
:
reject
,
notify
:
notify
};
});
expected
.
index
=
[
0
,
1
,
1
];
expected
.
value
=
[
1
,
2
,
3
];
setTimeout
(
function
()
{
firstResolver
.
notify
(
1
);
secondResolver
.
notify
(
2
);
},
0
);
setTimeout
(
function
()
{
secondResolver
.
notify
(
3
);
},
30
);
var
all_promise
=
RSVP
.
all
([
first
,
second
]).
then
(
null
,
null
,
function
(
value
)
{
count
+=
1
;
assert
.
equal
(
value
.
index
,
expected
.
index
.
shift
());
assert
.
equal
(
value
.
value
,
expected
.
value
.
shift
());
});
all_promise
.
cancel
();
setTimeout
(
function
()
{
assert
.
equal
(
count
,
3
);
done
();
},
50
);
});
});
describe
(
"
RSVP.any
"
,
function
()
{
...
...
@@ -908,7 +946,7 @@ describe("RSVP extensions", function() {
specify
(
'
cancel the remaining promises as soon as resolved
'
,
function
(
done
)
{
var
promise
=
new
RSVP
.
Promise
(
function
(
resolve
)
{
resolve
(
1
);
});
var
asyncPromise
=
new
RSVP
.
Promise
(
function
(
resolve
)
{
var
asyncPromise
=
new
RSVP
.
Promise
(
function
(
resolve
)
{
setTimeout
(
function
()
{
resolve
(
2
);
},
0
);
});
RSVP
.
any
([
promise
,
asyncPromise
]).
then
(
function
(
result
)
{
...
...
@@ -953,6 +991,44 @@ describe("RSVP extensions", function() {
done
();
},
20
);
});
specify
(
'
notifies promises progress
'
,
function
(
done
)
{
var
firstResolver
,
secondResolver
,
count
=
0
,
expected
=
{};
var
first
=
new
RSVP
.
Promise
(
function
(
resolve
,
reject
,
notify
)
{
firstResolver
=
{
resolve
:
resolve
,
reject
:
reject
,
notify
:
notify
};
});
var
second
=
new
RSVP
.
Promise
(
function
(
resolve
,
reject
,
notify
)
{
secondResolver
=
{
resolve
:
resolve
,
reject
:
reject
,
notify
:
notify
};
});
expected
.
index
=
[
0
,
1
,
1
];
expected
.
value
=
[
1
,
2
,
3
];
setTimeout
(
function
()
{
firstResolver
.
notify
(
1
);
secondResolver
.
notify
(
2
);
},
0
);
setTimeout
(
function
()
{
secondResolver
.
notify
(
3
);
},
30
);
var
all_promise
=
RSVP
.
any
([
first
,
second
]).
then
(
null
,
null
,
function
(
value
)
{
count
+=
1
;
assert
.
equal
(
value
.
index
,
expected
.
index
.
shift
());
assert
.
equal
(
value
.
value
,
expected
.
value
.
shift
());
});
all_promise
.
cancel
();
setTimeout
(
function
()
{
assert
.
equal
(
count
,
3
);
done
();
},
50
);
});
});
describe
(
"
RSVP.reject
"
,
function
(){
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment