New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: first implement #2
Conversation
support require index or files ```js const mkdirp = require('mz-modules').mkdirp; const mkdirp = require('mz-modules/mkdirp'); ``` modules - mkdirp - rimraf - sleep - nexttick - glob
Codecov Report
@@ Coverage Diff @@
## master #2 +/- ##
=======================================
Coverage ? 100%
=======================================
Files ? 8
Lines ? 24
Branches ? 0
=======================================
Hits ? 24
Misses ? 0
Partials ? 0
Continue to review full report at Codecov.
|
'use strict'; | ||
|
||
module.exports = { | ||
mkdirp: require('./mkdirp'), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
写成 getter 吧,要不然就变成只使用 sleep,然后所有模块都 require 进来了。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这个不改了吧,提供两种方式
nexttick.js
Outdated
@@ -0,0 +1,7 @@ | |||
'use strict'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
是不是也要一个 setImmediate ?
这不是推荐方式,看看 readme
fengmk2 <notifications@github.com>于2017年2月8日 周三22:37写道:
… ***@***.**** commented on this pull request.
------------------------------
In index.js
<#2 (review)>
:
> @@ -0,0 +1,9 @@
+'use strict';
+
+module.exports = {
+ mkdirp: require('./mkdirp'),
写成 getter 吧,要不然就变成只使用 sleep,然后所有模块都 require 进来了。
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#2 (review)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AAWA1WX8Xy6YXP0UGMbO-j7EK7C1vWGCks5radMQgaJpZM4L6thW>
.
|
加一下,我还在纠结要不要驼峰
fengmk2 <notifications@github.com>于2017年2月8日 周三22:41写道:
… ***@***.**** commented on this pull request.
------------------------------
In nexttick.js
<#2 (review)>
:
> @@ -0,0 +1,7 @@
+'use strict';
是不是也要一个 setImmediate ?
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#2 (review)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AAWA1bJS-Yhpy79pQComvCg8nhr0qVIDks5radQcgaJpZM4L6thW>
.
|
nexttick.js
Outdated
|
||
module.exports = () => { | ||
return new Promise(resolve => { | ||
process.nextTick(resolve); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
呃,我记得 Promise 默认就是自动加 nextTick 的,所以这里直接 return new Promise(resolve => { resolve(); });
就好
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nodejs/node#2736 (comment) Promise 默认在 nextTick 队列之后触发
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nextTick 感觉可以不提供了,需要的人直接写 yield Promise.resolve()
即可
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
可以这样写 module.exports = () => Promise.resolve();
实际测试 Promise.then()
好像是用的 setImmediate
而不是 process.nextTick
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
promise 没法做到 nextTick 的,感觉这个会有点误导?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
那还是用真的 nextTick 吧,不要 hack 了
nextTick.js 我改成大写吧,保持一致 |
写了个公用方法,再看看 |
改完了去各个仓库安利 |
过了 |
@@ -0,0 +1,3 @@ | |||
'use strict'; | |||
|
|||
module.exports = () => new Promise(resolve => setImmediate(resolve)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这个好像无解,只能这样。其实这里是 nextTick 然后再一次 setImmediate
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
promise 用的是 setImmediate,不是 nextTick,所以是 nextTick 无解。。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
process.nextTick(() => console.log(1));
Promise.resolve().then(() => console.log(2));
process.nextTick(() => console.log(3));
// =>
// 1
// 3
// 2
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
setImmediate(() => console.log(1));
Promise.resolve().then(() => console.log(2));
setImmediate(() => console.log(3));
// =>
// 2
// 1
// 3
额,都不是,尴尬了。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Promise.resolve 在 nextTick 之后,setImmediate 之前。所以相对于 nextTick,setImmediate 了
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
是的,这里要不换一个没这么歧义的名字?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
把这个用例加上
用例加了 |
npminstall 跑太慢,测试过了 |
support require index or files
modules
mz-modules/mkdirp
wrapped mkdirpmz-modules/rimraf
wrapped rimrafmz-modules/glob
wrapped globmz-modules/sleep
wrapped ko-sleepmz-modules/nextTick
wrapped process.nextTickmz-modules/setImmediate
wrapped setImmediateCloses #1