Skip to content
Toggle navigation
Projects
Groups
Snippets
Help
public
/
sequelize
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
不要怂,就是干,撸起袖子干!
Commit db627a3b
authored
May 11, 2015
by
Manuel Darveau
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fixed Promise-CLS shim for 'each' and other methods.
1 parent
3dd94d84
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
43 additions
and
16 deletions
lib/promise.js
package.json
lib/promise.js
View file @
db627a3
'use strict'
;
'use strict'
;
var
Promise
=
require
(
'bluebird'
)
var
Promise
=
require
(
'bluebird'
)
,
_then
=
Promise
.
prototype
.
_then
;
,
shimmer
=
require
(
'shimmer'
);
Promise
.
prototype
.
_then
=
function
(
didFulfill
,
didReject
,
didProgress
,
receiver
,
internalData
)
{
// functionName: The Promise function that should be shimmed
if
(
Promise
.
Sequelize
.
cls
)
{
// fnArgs: The arguments index that should be CLS enabled (typically all callbacks). Offset from last if negative
var
ns
=
Promise
.
Sequelize
.
cls
;
function
shimCLS
(
object
,
functionName
,
fnArgs
){
if
(
typeof
didFulfill
===
'function'
)
didFulfill
=
ns
.
bind
(
didFulfill
);
shimmer
.
wrap
(
object
,
functionName
,
function
(
fn
)
{
if
(
typeof
didReject
===
'function'
)
didReject
=
ns
.
bind
(
didReject
);
return
function
()
{
if
(
typeof
didProgress
===
'function'
)
didProgress
=
ns
.
bind
(
didProgress
);
if
(
Promise
.
Sequelize
&&
Promise
.
Sequelize
.
cls
)
{
}
var
ns
=
Promise
.
Sequelize
.
cls
;
for
(
var
x
=
0
;
x
<
fnArgs
.
length
;
x
++
)
{
return
_then
.
call
(
this
,
didFulfill
,
didReject
,
didProgress
,
receiver
,
internalData
);
var
argIndex
=
x
<
0
?
arguments
.
length
+
x
:
x
;
};
if
(
argIndex
<
arguments
.
length
&&
typeof
arguments
[
argIndex
]
===
'function'
)
arguments
[
argIndex
]
=
ns
.
bind
(
arguments
[
argIndex
]
);
}
module
.
exports
=
Promise
;
}
\ No newline at end of file
return
fn
.
apply
(
this
,
arguments
);
};
});
}
// Core
shimCLS
(
Promise
,
'join'
,
[
-
1
]);
shimCLS
(
Promise
,
'try'
,
[
0
]);
shimCLS
(
Promise
,
'method'
,
[
0
]);
shimCLS
(
Promise
.
prototype
,
'then'
,
[
0
,
1
,
2
]);
shimCLS
(
Promise
.
prototype
,
'spread'
,
[
0
,
1
]);
shimCLS
(
Promise
.
prototype
,
'catch'
,
[
-
1
]);
shimCLS
(
Promise
.
prototype
,
'error'
,
[
0
]);
shimCLS
(
Promise
.
prototype
,
'finally'
,
[
0
]);
// Collections
shimCLS
(
Promise
.
prototype
,
'map'
,
[
0
]);
shimCLS
(
Promise
.
prototype
,
'reduce'
,
[
0
]);
shimCLS
(
Promise
.
prototype
,
'filter'
,
[
0
]);
shimCLS
(
Promise
.
prototype
,
'each'
,
[
0
]);
// Utility
shimCLS
(
Promise
.
prototype
,
'tap'
,
[
0
]);
module
.
exports
=
Promise
;
package.json
View file @
db627a3
...
@@ -40,7 +40,8 @@
...
@@ -40,7 +40,8 @@
"moment"
:
"^2.9.0"
,
"moment"
:
"^2.9.0"
,
"node-uuid"
:
"~1.4.1"
,
"node-uuid"
:
"~1.4.1"
,
"toposort-class"
:
"~0.3.0"
,
"toposort-class"
:
"~0.3.0"
,
"validator"
:
"^3.34.0"
"validator"
:
"^3.34.0"
,
"shimmer"
:
"1.0.0"
},
},
"devDependencies"
:
{
"devDependencies"
:
{
"chai"
:
"^2.1.2"
,
"chai"
:
"^2.1.2"
,
...
...
Write
Preview
Markdown
is supported
Attach a file
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 post a comment