jsDoc 辅助vsocde函数参数提示
jsDoc 辅助函数参数提示
/*** 模拟请求的异步函数* ```javascript* // 省略时间传值* sleep({ data: '返回值', code: 200 }).then(res => console.log(res))* // 也可以自己加时间* sleep({ data: '返回值', code: 200 }, 2000).then(res => console.log(res))* ```* @template R* @param {R} args 模拟请求返回的参数* @param {number} [time_ms=1000] 模拟请求消耗的时间毫秒 默认 1000ms* @return {Promise} 返回值*/
export const sleep = (args, time_ms = 1000) => new Promise((resolve) => setTimeout(resolve, time_ms, args))
/*** 模拟请求的异步函数* ```javascript* // 省略时间传值* sleep({ msg: 'success' }, { msg: 'error' }).then(res => console.log(res))* // 也可以自己加时间* sleep({ msg: 'success' }, { msg: 'error' }, 500).then(res => console.log(res))* ```* @template R* @template J* @param {R} resolveData 模拟请求成功返回的参数* @param {J} rejectData 模拟请求失败返回的参数* @param {number} [time_ms=1000] 模拟请求消耗的时间毫秒 默认 1000ms* @return {Promise} 返回值*/
export const sleep = (resolveData,rejectData,time_ms = 1000,random = Math.floor(Math.random() * 2), // 随机 1,0 模拟请求成功失败
) => new Promise((resolve, reject) =>setTimeout(random ? resolve : reject, time_ms, random ? resolveData : rejectData))sleep({ msg: 'success' }, { msg: 'error' }).then(res => console.log(res)).catch(res => { console.log(res) })
本文来自互联网用户投稿,文章观点仅代表作者本人,不代表本站立场,不承担相关法律责任。如若转载,请注明出处。 如若内容造成侵权/违法违规/事实不符,请点击【内容举报】进行投诉反馈!
