将小游戏同步 API 转换为返回 IOResult<T> 的新函数。
IOResult<T>
功能类似于 tryGeneralSyncOp,但以函数包装的方式使用,将可能抛出的异常捕获并转换为 IOResult。
tryGeneralSyncOp
IOResult
小游戏同步 API。
返回一个新的函数,该函数返回 IOResult<T>。
2.0.0
// 将 wx.getStorageSync 转换为 IOResult 风格const getStorageSync = syncIOResultify(wx.getStorageSync);const result = getStorageSync('test');if (result.isOk()) { console.log('获取成功:', result.unwrap());} else { console.error('获取失败:', result.unwrapErr().message);} Copy
// 将 wx.getStorageSync 转换为 IOResult 风格const getStorageSync = syncIOResultify(wx.getStorageSync);const result = getStorageSync('test');if (result.isOk()) { console.log('获取成功:', result.unwrap());} else { console.error('获取失败:', result.unwrapErr().message);}
将小游戏同步 API 转换为返回
IOResult<T>的新函数。功能类似于
tryGeneralSyncOp,但以函数包装的方式使用,将可能抛出的异常捕获并转换为IOResult。