co

Getting a promise's value via yield & co

拥有回忆 提交于 2019-11-29 06:23:23
I'm trying to figure out how to get the value of a promise via yield , possibly with "co": function *(){ var someVar = yield functionThatReturnsAPromise(); } The called function is not a generator, just a normal function. With the above, someVar == Promise , but I want the resolved value. Does co or some other library have a way of doing this? Yes, co can do that. You'll have to wrap parent function inside co call: co(function *(){ var someVar = yield functionThatReturnsAPromise(); })() someVar inside will become resolved value. If promise gets rejected, error can be cought with basic try {}

创建SVN代码托管

让人想犯罪 __ 提交于 2019-11-28 18:16:41
在我们开发过程中,避免不了要使用svn,如果不是从初始版本入手的话,很可能你需要使用co,up,st,diff,ci等几个命令,这些都是比较常用的,在下面我们讲述的是 如何将整个工程,传到SVN创建初始版本 。 在这里我们的项目房子baseFont中,目录结果如下:其中 文件夹dist和node_modules是运行时文件夹 ,没有必要加入到svn版本管理之后。 --baseFont ----app/ ----dist/ ----Gruntfile.js ----js/ ----.jshintrc ----node_modules/ 。。。。。 导入-import/mkdir svn import baseFont svn://git.oschina.net/wjzk/baseFont -m 'create folder' --depth empty 这个命令中使用了 --depth empty 意思是之创建文件夹 baseFont ,而不inport任何文件夹,这样可以便于我们有选择的只上传需要的代码,而忽略掉不必须要的代码。同意也可以使用如下代码创建文件夹,效果是同等的: svn mkdir svn://git.oschina.net/wjzk/baseFont -m 'create folder' 导出工程-co svn co --depth=empty svn://git

Understanding code flow with yield/generators

|▌冷眼眸甩不掉的悲伤 提交于 2019-11-26 05:38:57
问题 I\'ve read over several examples of code using JavaScript generators such as this one. The simplest generator-using block I can come up with is something like: function read(path) { return function (done) { fs.readFile(path, \"file\", done); } } co(function *() { console.log( yield read(\"file\") ); })(); This does indeed print out the contents of file , but my hangup is where done is called. Seemingly, yield is syntactic sugar for wrapping what it returns to in a callback and assigning the