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
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
rsvp.js
Commits
6dd93886
Commit
6dd93886
authored
Feb 27, 2013
by
Yehuda Katz
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Remove build artifacts
parent
420f268c
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
1 addition
and
156 deletions
+1
-156
.gitignore
.gitignore
+1
-0
main.js
main.js
+0
-156
No files found.
.gitignore
View file @
6dd93886
/node_modules
/main.js
/promise-tests/
/promises-tests/
/promises-aplus-tests/
...
...
main.js
deleted
100644 → 0
View file @
420f268c
"
use strict
"
;
var
async
=
require
(
"
rsvp/async
"
).
async
;
var
EventTarget
=
require
(
"
rsvp/events
"
).
EventTarget
;
var
config
=
{};
config
.
async
=
async
;
var
noop
=
function
()
{};
var
Promise
=
function
(
resolver
)
{
var
promise
=
this
;
var
resolvePromise
=
function
(
value
)
{
resolve
(
promise
,
value
);
resolvePromise
=
noop
;
rejectPromise
=
noop
;
};
var
rejectPromise
=
function
(
value
)
{
reject
(
promise
,
value
);
resolvePromise
=
noop
;
rejectPromise
=
noop
;
};
this
.
on
(
'
promise:resolved
'
,
function
(
event
)
{
this
.
trigger
(
'
success
'
,
{
detail
:
event
.
detail
});
},
this
);
this
.
on
(
'
promise:failed
'
,
function
(
event
)
{
this
.
trigger
(
'
error
'
,
{
detail
:
event
.
detail
});
},
this
);
if
(
resolver
)
{
resolver
(
resolvePromise
,
rejectPromise
);
}
};
var
invokeCallback
=
function
(
type
,
promise
,
callback
,
event
)
{
var
hasCallback
=
typeof
callback
===
'
function
'
,
value
,
error
,
succeeded
,
failed
;
if
(
hasCallback
)
{
try
{
value
=
callback
(
event
.
detail
);
succeeded
=
true
;
}
catch
(
e
)
{
failed
=
true
;
error
=
e
;
}
}
else
{
value
=
event
.
detail
;
succeeded
=
true
;
}
if
(
value
&&
typeof
value
.
then
===
'
function
'
)
{
value
.
then
(
function
(
value
)
{
resolve
(
promise
,
value
);
},
function
(
error
)
{
reject
(
promise
,
error
);
});
}
else
if
(
hasCallback
&&
succeeded
)
{
resolve
(
promise
,
value
);
}
else
if
(
failed
)
{
reject
(
promise
,
error
);
}
else
if
(
type
===
'
resolve
'
)
{
resolve
(
promise
,
value
);
}
else
if
(
type
===
'
reject
'
)
{
reject
(
promise
,
value
);
}
};
Promise
.
prototype
=
{
then
:
function
(
done
,
fail
)
{
var
thenPromise
=
new
Promise
();
if
(
this
.
isFulfilled
)
{
config
.
async
(
function
()
{
invokeCallback
(
'
resolve
'
,
thenPromise
,
done
,
{
detail
:
this
.
fulfillmentValue
});
},
this
);
}
if
(
this
.
isRejected
)
{
config
.
async
(
function
()
{
invokeCallback
(
'
reject
'
,
thenPromise
,
fail
,
{
detail
:
this
.
rejectedReason
});
},
this
);
}
this
.
on
(
'
promise:resolved
'
,
function
(
event
)
{
invokeCallback
(
'
resolve
'
,
thenPromise
,
done
,
event
);
});
this
.
on
(
'
promise:failed
'
,
function
(
event
)
{
invokeCallback
(
'
reject
'
,
thenPromise
,
fail
,
event
);
});
return
thenPromise
;
}
};
function
resolve
(
promise
,
value
)
{
config
.
async
(
function
()
{
promise
.
trigger
(
'
promise:resolved
'
,
{
detail
:
value
});
promise
.
isFulfilled
=
true
;
promise
.
fulfillmentValue
=
value
;
});
}
function
reject
(
promise
,
value
)
{
config
.
async
(
function
()
{
promise
.
trigger
(
'
promise:failed
'
,
{
detail
:
value
});
promise
.
isRejected
=
true
;
promise
.
rejectedReason
=
value
;
});
}
function
all
(
promises
)
{
var
i
,
results
=
[];
var
allPromise
=
new
Promise
();
var
remaining
=
promises
.
length
;
if
(
remaining
===
0
)
{
resolve
(
allPromise
,
[]);
}
var
resolver
=
function
(
index
)
{
return
function
(
value
)
{
resolveAll
(
index
,
value
);
};
};
var
resolveAll
=
function
(
index
,
value
)
{
results
[
index
]
=
value
;
if
(
--
remaining
===
0
)
{
resolve
(
allPromise
,
results
);
}
};
var
rejectAll
=
function
(
error
)
{
reject
(
allPromise
,
error
);
};
for
(
i
=
0
;
i
<
remaining
;
i
++
)
{
promises
[
i
].
then
(
resolver
(
i
),
rejectAll
);
}
return
allPromise
;
}
EventTarget
.
mixin
(
Promise
.
prototype
);
function
configure
(
name
,
value
)
{
config
[
name
]
=
value
;
}
exports
.
Promise
=
Promise
;
exports
.
all
=
all
;
exports
.
configure
=
configure
;
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