我被引导相信Promise.all会并行执行你传递它的所有函数,而不关心返回的promises完成的顺序.
但是当我写这个测试代码时:
function Promise1(){
return new Promise(function(resolve, reject){
for(let i = 0; i < 10; i++){
console.log("Done Err!");
}
resolve(true)
})
}
function Promise2(){
return new Promise(function(resolve, reject){
for(let i = 0; i < 10; i++){
console.log("Done True!");
}
resolve(true)
})
}
Promise.all([
Promise1(),
Promise2()
])
.then(function(){
console.log("All Done!")
})
Run Code Online (Sandbox Code Playgroud)
我得到的结果就是这个
Done Err!
Done Err!
Done Err!
Done Err!
Done Err!
Done Err!
Done Err!
Done Err!
Done Err!
Done Err!
Done True!
Done True!
Done True!
Done True!
Done …Run Code Online (Sandbox Code Playgroud) 我正在为我的键盘修改一些驱动程序软件,其中一部分是将日期输出到键盘屏幕的插件.目前它说1月1日,但我真的希望它说第1,第2,第3或第4或其他什么.
我一直在寻找各种代码,这些代码会给我一些关于如何做到这一点的想法,但我只能找到C#的例子而且我正在使用C.
编辑:
const char *ordinals[] = {"", "1st", "2nd", "3rd", "4th", "5th", "6th", "7th", "8th", "9th", "10th", "11th", "12th", "13th", "14th", "15th", "16th", "17th", "18th", "19th", "20th", "21st", "22nd", "23rd", "24th", "25th", "26th", "27th", "28th", "29th", "30th", "31st"};
sprintf(date, "%s %s", ordinals[t->tm_mday], mon);
Run Code Online (Sandbox Code Playgroud)