lr6 / blog Goto Github PK
View Code? Open in Web Editor NEWmy blog
my blog
Promise.any
接收一个 promise
可迭代对象promise
成功,就返回那个已经成功的 promise
promise
成功(即所有的 promises
都失败/拒绝),Promise.any 将返回异步失败,和一个 AggregateError 对象,它继承自 Error,有一个 error 属性,属性值是由所有失败值填充的数组。// 至少有一个成功
const pErr = new Promise((resolve, reject) => {
reject("总是失败")
})
const pSlow = new Promise((resolve, reject) => {
setTimeout(resolve, 500, "最终完成")
})
const pFast = new Promise((resolve, reject) => {
setTimeout(resolve, 100, "很快完成")
})
Promise.any([pErr, pSlow, pFast]).then((value) => {
console.log(value)
})
// 期望输出: "很快完成"
// 全部(失败 or 拒绝)
const pImmediatelyErr = new Promise((resolve, reject) => {
reject("总是失败")
})
const pSlowErr = new Promise((resolve, reject) => {
setTimeout(reject, 500, "最终失败")
})
const pFastErr = new Promise((resolve, reject) => {
setTimeout(reject, 100, "很快失败")
})
Promise.any([pImmediatelyErr, pSlowErr, pFastErr]).catch((err) => {
console.log(err)
})
// 期望输出: "AggregateError: All promises were rejected"
方法 | 描述 | 标准 |
---|---|---|
Promise.any() | 只要有一个 Promise 成功,立即返回成功,全部失败返回 AggregateError | ES-2021 |
Promise.allSettled() | 所有 Promise 完成才返回(无论成功 or 失败),返回结果数组 | ES-2020 |
Promise.race() | 只要迭代器中的一个 Promise 完成就返回结果(无论结果是成功 or 失败) | ES-2015 |
Promise.all() | 只要一个 Promise 失败,立即返回失败,全成功返回成功数组 | ES-2015 |
推荐阅读
es2021之前提供的字符串替换方法 replace方法 ,当一个参数是字符串时,只替换第一个匹配的字符串
'ASDFA'.replace('A', 'M')
// "MSDFA"
如果需要替换所有匹配的字符串,第一个参数需要使用正则
'ASDFA'.replace(/A/g, 'M')
// "MSDFM"
有了 replaceAll 方法,可直接替换全部匹配的字符,不再需要使用正则
'ASDFA'.replaceAll('A', 'M')
"MSDFM"
推荐阅读
以前写大数时,过长的话不同容易读取
100000000
// 1e
现在为了提高可读性,使用下划线作为数字的分隔符
100_000_000
// 1e
1_0000_0000
// 1e
推荐阅读
待写
待写
server {
listen 80;
listen [::]:80;
server_name localhost;
root /usr/share/nginx/html;
index index.html index.htm;
location / {
try_files $uri $uri/ /index.html;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
}
npm
在安装部分依赖( 如node-sass
等 )的时候,会去下载一些依赖的二进制文件,由于不可言原因,总是下载失败。这里把常用的报错地址换成镜像地址,下载就不会报错了。
# === NPM BINRAY CHINA ===
# https://github.com/cnpm/binary-mirror-config/blob/master/package.json#L48
export NODEJS_ORG_MIRROR="https://cdn.npmmirror.com/binaries/node"
export NVM_NODEJS_ORG_MIRROR="https://cdn.npmmirror.com/binaries/node"
export PHANTOMJS_CDNURL="https://cdn.npmmirror.com/binaries/phantomjs"
export CHROMEDRIVER_CDNURL="https://cdn.npmmirror.com/binaries/chromedriver"
export OPERADRIVER_CDNURL="https://cdn.npmmirror.com/binaries/operadriver"
export ELECTRON_MIRROR="https://cdn.npmmirror.com/binaries/electron/"
export ELECTRON_BUILDER_BINARIES_MIRROR="https://cdn.npmmirror.com/binaries/electron-builder-binaries/"
export SASS_BINARY_SITE="https://cdn.npmmirror.com/binaries/node-sass"
export SWC_BINARY_SITE="https://cdn.npmmirror.com/binaries/node-swc"
export NWJS_URLBASE="https://cdn.npmmirror.com/binaries/nwjs/v"
export PUPPETEER_DOWNLOAD_HOST="https://cdn.npmmirror.com/binaries"
export SENTRYCLI_CDNURL="https://cdn.npmmirror.com/binaries/sentry-cli"
export SAUCECTL_INSTALL_BINARY_MIRROR="https://cdn.npmmirror.com/binaries/saucectl"
export npm_config_sharp_binary_host="https://cdn.npmmirror.com/binaries/sharp"
export npm_config_sharp_libvips_binary_host="https://cdn.npmmirror.com/binaries/sharp-libvips"
export npm_config_robotjs_binary_host="https://cdn.npmmirror.com/binaries/robotj"
etc\profile.d\bash_profile.sh
C:\Program Files\Git\etc\profile.d\bash_profile.sh
前端开发往往需要在不同的 node
版本之间切换,,nvm
是比较流行好用的 node
版本管理工具
node
和nvm
删除指的是直接卸载,不是删除文件夹 (有则删除,没有则略过这一步)
nvm
# 查看nvm的文档
nvm help
nvm
的安装目录下的 settings.txt
文件,添加镜像node_mirror: https://npmmirror.com/mirrors/node/
npm_mirror: https://npmmirror.com/mirrors/npm/
# 查询nvm的安装目录
where nvm
# 查看内核
unname -a
# 查看服务器环境
cat /etc/os-release
lscpu
默认在Linux服务器中,cpu
信息都保存在/proc/cpuinfo
文件中,通过cat
命令结合grep
命令我们可以很容易查询出来
# 查看CPU型号信息
cat /proc/cpuinfo | grep name | cut -f2 -d: | uniq -c
# 查看物理CPU个数
cat /proc/cpuinfo| grep "physical id"| sort| uniq| wc -l
# 每个物理CPU中的核数
cat /proc/cpuinfo| grep "cpu cores"| uniq
# 查看逻辑CPU的个数
cat /proc/cpuinfo| grep "processor"| wc -l
free -h
env
# Install GPG keys
gpg --keyserver keyserver.ubuntu.com --recv-key 409B6B1796C275462A1703113804BB82D39DC0E3 7D2BAF1CF37B13E2069D6956105BD0E739499BDB
# 安装 rvm ruby rails
curl -sSL https://get.rvm.io | bash -s stable --rails
# 安装 nginx
yum install nginx
# 查看nginx的位置
which nginx
# 进入到安装目录
cd ${nginx dir}
# 执行
./nginx
centos7
内置的防火墙已经从iptables
变成了 firewalld
# 查看防火墙配置
firewall-cmd --list-all
# 添加开放的端口
firewall-cmd --add-service=http --permanent
firewall-cmd --add-port=80/tcp --permanent
# 重启防火墙
firewall-cmd --reload
先写这么多,用到其他的命令,再添加上来。
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.