首页 \ 问答 \ ConcurrentHashMap与同步HashMap(ConcurrentHashMap vs Synchronized HashMap)

ConcurrentHashMap与同步HashMap(ConcurrentHashMap vs Synchronized HashMap)

HashMapConcurrentHashMap上使用包装器类SynchronizedMap什么区别? 是否只能在迭代它时修改HashMapConcurrentHashMap )?


What is the difference between using the wrapper class, SynchronizedMap, on a HashMap and ConcurrentHashMap? Is it just being able to modify the HashMap while iterating it (ConcurrentHashMap)?


原文:https://stackoverflow.com/questions/1291836
更新时间:2022-06-09 17:06

最满意答案

没有理由你必须调用Promise.resolve来获取值。 请记住,Promises是异步的。 你必须像这样访问它的价值:

myPromise.then(value => {
  console.log(value)
  // do whatever you're going to do with value
};

你可以阅读更多关于Promises如何工作的[这里] [1]。


There's no reason for you to have to call Promise.resolve to get the value. Remember that Promises are asynchronous. You have to access it's value like this:

myPromise.then(value => {
  console.log(value)
  // do whatever you're going to do with value
};

You can read up more [here][1] on how Promises work.

相关问答

更多
  • 没有理由你必须调用Promise.resolve来获取值。 请记住,Promises是异步的。 你必须像这样访问它的价值: myPromise.then(value => { console.log(value) // do whatever you're going to do with value }; 你可以阅读更多关于Promises如何工作的[这里] [1]。 There's no reason for you to have to call Promise.resolve to get ...
  • 不,没有其他方法可以做到这一点 - 我唯一可以说的是这个用例并不常见。 就像费利克斯在评论中说的一样 - 你会做什么会一直工作。 值得一提的是,承诺构造函数以这种方式表现的原因是抛出安全性 - 如果您的代码在promise构造函数中运行时发生异常,则会发生异常,这将导致拒绝,这种形式的抛出安全 - 将抛出的错误转换为拒绝是重要的,有助于维护可预测的代码。 对于这种抛出的安全原因,承诺构造函数被选择为延迟(这是一种替代的承诺构造方式,可以允许您正在做的) - 对于最佳实践 - 我会传递元素并使用promise ...
  • 只需将它们保存在封盖内。 var makePromise = function () { var resolvePromise = null, rejectPromise = null, promise = new Promise(function (resolve, reject) { resolvePromise = resolve; rejectPromise = reject; }); ...
  • 您需要通过调用它的构造函数调用它在回调中提供的函数来解析promise。 const promise = new Promise((resolve, reject) => { // you must call resolve() or reject() here // otherwise the promise never resolves }); 否则它将始终处于Pending状态,并且永远不会调用您传入的回调。 promise.then(() => { // this never gets ...
  • 这是deferred模式的变体,除了您使用promise对象中的resolve / reject函数返回promise对象。 原始deferred模式分别创建了具有promise和resolve / reject函数的对象。 因此,您可以在不暴露控件的情况下传递承诺。 说实话,很少有地方需要实际打破构造函数范围。 在我看来,使用这种模式犯一个错误并且最终得到未解决的承诺比使用构造函数模式更容易一点。 据我所知,构造函数模式对延迟模式的唯一好处就是你可以立即抛出并拒绝承诺(通过同步错误)。 This is a ...
  • 第一个问题 Promise.all承诺一系列承诺 更改: Promise.all(read_csv_file("devices.csv"), read_csv_file("bugs.csv")) 到(添加[]参数) Promise.all([read_csv_file("devices.csv"), read_csv_file("bugs.csv")]) // ---------^-------------------------------------------------------^ 第二个问题 ...
  • 你可以使用Array map (如果必须的话还是_.map)和Promise.all来实现你想要的 setNewCacheUrls(providedUrls: any, nativeURL: string): Promise { return Promise.all(_.map(providedUrls, url => { const fileTransfer: TransferObject = this.transfer.create(); return ...
  • new Promise构造函数将特定函数传递给您的回调函数,该函数将成为您的resolve参数。 这个承诺(你用new Promise构建的那个new Promise )只能通过调用特定的resolve函数来resolve 。 Promise.resolve只是创造了一个新的“预先解决”的承诺。 它没有解决任何现有的承诺(也没有任何方式知道它应该解决哪个承诺)。 The new Promise constructor passes a specific function into your callback ...
  • 首先是关于孩子的承诺。 我想你的意思是: requestAnimationFrame(function () { //.... }); 这实际上并不是一个承诺,而是一个(更基本的)回调实现,在完成某些事情时会调用它。 在这种情况下,当下一个涂料循环发生时。 不要惊讶于可以从该回调中调用resolve 。 没有规则说你不能这样做: resolve仍然在该功能范围内。 在该回调中再次调用requestAnimationFrame的原因是为了确保重新绘制已经发生,这在您等待2个周期时是肯定的。 然后调用r ...
  • 你有一个g变量,你检查0但你没有在任何地方定义g 。 您没有看到这一点的原因是本机(或jQuery)承诺不会自动跟踪可能未处理的拒绝。 您可以通过将.catch附加到链的末尾来查看是否有错误来检查错误。 q.then(function (result) { ... }).catch(function(e){ console.log(e.message); console.log(e.stack); }); 哪个会告诉你这个问题。 或者,使用像Bluebird这样更强大的库,在未 ...

相关文章

更多

最新问答

更多
  • 您如何使用git diff文件,并将其应用于同一存储库的副本的本地分支?(How do you take a git diff file, and apply it to a local branch that is a copy of the same repository?)
  • 将长浮点值剪切为2个小数点并复制到字符数组(Cut Long Float Value to 2 decimal points and copy to Character Array)
  • OctoberCMS侧边栏不呈现(OctoberCMS Sidebar not rendering)
  • 页面加载后对象是否有资格进行垃圾回收?(Are objects eligible for garbage collection after the page loads?)
  • codeigniter中的语言不能按预期工作(language in codeigniter doesn' t work as expected)
  • 在计算机拍照在哪里进入
  • 使用cin.get()从c ++中的输入流中丢弃不需要的字符(Using cin.get() to discard unwanted characters from the input stream in c++)
  • No for循环将在for循环中运行。(No for loop will run inside for loop. Testing for primes)
  • 单页应用程序:页面重新加载(Single Page Application: page reload)
  • 在循环中选择具有相似模式的列名称(Selecting Column Name With Similar Pattern in a Loop)
  • System.StackOverflow错误(System.StackOverflow error)
  • KnockoutJS未在嵌套模板上应用beforeRemove和afterAdd(KnockoutJS not applying beforeRemove and afterAdd on nested templates)
  • 散列包括方法和/或嵌套属性(Hash include methods and/or nested attributes)
  • android - 如何避免使用Samsung RFS文件系统延迟/冻结?(android - how to avoid lag/freezes with Samsung RFS filesystem?)
  • TensorFlow:基于索引列表创建新张量(TensorFlow: Create a new tensor based on list of indices)
  • 企业安全培训的各项内容
  • 错误:RPC失败;(error: RPC failed; curl transfer closed with outstanding read data remaining)
  • C#类名中允许哪些字符?(What characters are allowed in C# class name?)
  • NumPy:将int64值存储在np.array中并使用dtype float64并将其转换回整数是否安全?(NumPy: Is it safe to store an int64 value in an np.array with dtype float64 and later convert it back to integer?)
  • 注销后如何隐藏导航portlet?(How to hide navigation portlet after logout?)
  • 将多个行和可变行移动到列(moving multiple and variable rows to columns)
  • 提交表单时忽略基础href,而不使用Javascript(ignore base href when submitting form, without using Javascript)
  • 对setOnInfoWindowClickListener的意图(Intent on setOnInfoWindowClickListener)
  • Angular $资源不会改变方法(Angular $resource doesn't change method)
  • 在Angular 5中不是一个函数(is not a function in Angular 5)
  • 如何配置Composite C1以将.m和桌面作为同一站点提供服务(How to configure Composite C1 to serve .m and desktop as the same site)
  • 不适用:悬停在悬停时:在元素之前[复制](Don't apply :hover when hovering on :before element [duplicate])
  • 常见的python rpc和cli接口(Common python rpc and cli interface)
  • Mysql DB单个字段匹配多个其他字段(Mysql DB single field matching to multiple other fields)
  • 产品页面上的Magento Up出售对齐问题(Magento Up sell alignment issue on the products page)