小编Man*_*dha的帖子

多个onCompletion适用于Scala的Futures

在Scala中试用Futures时,我注意到对OnCompletion的多次调用都有效!

问题1 - 显然,我不应该以这种方式编写代码,但我想知道编译器是否应该在这种情况下引发错误?

import scala.concurrent._
import scala.concurrent.ExecutionContext.Implicits.global
import scala.util.{Failure,Success}

object ConcurrencyExample extends App {
  val time = System.currentTimeMillis()

  println("looking at inventory")
  //create code we want to execute concurrently
  val f: Future[Int] = Future //or just f = Future
  {
    println("add item to shopping basket")
    Thread.sleep(30) //simulate backend process delay
    println("Item added")
    1 //simulate the no. of items in basket

  }

//this works
  f onComplete (x => println("on complete1 " + x))
//and this too
  f onComplete {
    case Success(value) …
Run Code Online (Sandbox Code Playgroud)

scala

3
推荐指数
1
解决办法
976
查看次数

collect vs collectFirst-为什么返回值的类型不同-Scala

问题是确认我是否正确理解Option的使用。

我注意到方法collect返回一个List,而collectFirst返回一个Option。是否是因为collect可以返回多个值或不返回任何值(没有一个由空列表表示)。另一方面,collectFirst返回单个值(或不返回任何值),因此使用Option会更多,因为我们永远不会返回“列表”

scala

2
推荐指数
1
解决办法
3437
查看次数

没有return语句的Some/None中的垃圾值

如果我不使用'return'语句,为什么下面的代码(斐波纳契系列)表现不同.我以为我们不需要'回归'.

def nthFibonacci(nth:Int): Option[Int] = {
  @annotation.tailrec
  def go(previousNo:Int, nextNo:Int, currentCount:Int, nth:Int):Option[Int]= {
    if (currentCount == nth) Some(previousNo)
    else go(nextNo,previousNo+nextNo,currentCount+1,nth)
  }

  if (nth<=0) None //invalid argument check
  if (nth==1) Some(0) //first fibonacci
  if (nth == 2) Some(1) //second fibonacci
  go(1,(0+1),2,nth)
}
Run Code Online (Sandbox Code Playgroud)

//对于n = 0,1我得到垃圾,而我应该得到无或有些.

nthFibonacci(0)res0:Option [Int] = Some(1070270178)

nthFibonacci(1)res1:选项[Int] =部分(-2140540357)

nthFibonacci(2)res2:选项[Int] =一些(1)

有趣的是,如果我更改代码并添加'return',代码就可以了!if(nth <= 0)返回无//无效参数检查if(nth == 1)return some(0)// first fibonacci if(nth == 2)return Some(1)// second fibonacci go(1, (0 + 1),2,第n个)

nthFibonacci (0)
res0: Option[Int] = None

nthFibonacci(1)
res1: Option[Int] = …
Run Code Online (Sandbox Code Playgroud)

scala return

2
推荐指数
1
解决办法
49
查看次数

如何在 Windows 上执行节点脚本(#!/usr/bin/env 节点)?

我想检查protractor我的 Windows 机器上的命令版本。我输入了以下内容,但没有用。为什么?路径是正确的。

./node_modules/protractor/bin/protractor --version
'.' is not recognized as an internal or external command,
operable program or batch file.
Run Code Online (Sandbox Code Playgroud)

该文件是一个脚本 -

#!/usr/bin/env node

process.env.NODE_ENV = process.env.NODE_ENV || 'test';

require('../built/cli.js');
Run Code Online (Sandbox Code Playgroud)

我可以在 Windows 中使用 Bash 运行它,但是有没有办法在 CMD 上运行它?

windows bash cmd

2
推荐指数
1
解决办法
1516
查看次数

`path must start with the project source root` ng serve 错误

我想在我的项目中使用jquery和。该项目是在目录中,并且文件在路径。我正在尝试按如下方式引用和文件,但是在目录中运行时,出现错误 - 。我究竟做错了什么?bootstrapAngular-CLIAngular-CLIproject/uijquerybootstrapproject/public/...jquerybootstrapangular.jsonng serveproject/uiThe ./../public/images/favicon.png asset path must start with the project source root

的片段angular.json

"projects": {
    "ui": {
      "root": "",
      "sourceRoot": "src",
      "projectType": "application",
      "architect": {
        "build": {
          "builder": "@angular-devkit/build-angular:browser",
          "options": {
            "outputPath": "dist",
            "index": "src/index.html",
            "main": "src/main.ts",
            "tsConfig": "src/tsconfig.app.json",
            "polyfills": "src/polyfills.ts",
            "assets": [
              "src/assets",
              "./../public/images/favicon.png"
            ],
            "styles": [
              "src/styles.css",
              "./../public/stylesheets/common/css-reset.css",
              "./../public/stylesheets/common/common-styles.css",
              "./../public/stylesheets/common/vendor/bootstrap/bootstrap.css"
            ],
            "scripts": [
              "./../public/javascripts/common/vendor/jquery/jquery-3.2.1.js",
              "./../public/javascripts/common/vendor/bootstrap/bootstrap.js"
            ]
          },
Run Code Online (Sandbox Code Playgroud)

angular-cli-v6

2
推荐指数
1
解决办法
8030
查看次数

JsValue中validate和validateOpt的区别

JsValue 有两种方法

def validate[A](implicit rds: Reads[A]): JsResult[A] - 尝试将节点转换为 JsResult[T](成功或错误)。

def validateOpt[A](implicit rds: Reads[A]): JsResult[Option[A]] - 我想它也做同样的事情。

在什么情况下会validateOpt用到?在我看来,如果JsResult失败,那么我会在JsError. 那么,Option在成功转换为类型后,额外的in JsSuccessas层JsSuccess将始终包含值有什么意义呢?JsValueA

scala playframework play-json playframework-2.6

2
推荐指数
1
解决办法
316
查看次数

ace.js 和 Angular 的主题和模式路径推断问题

抱歉,不幸的是,这个问题没有提供太多细节,因为我不确定到底需要什么来解释这个问题。首先,我尝试ng2-ace-editor在我的Angular应用程序中使用。但我的设置并不标准。详细信息在另一个相关问题 -应用程序找不到 .js 文件

总之,如果我明确地包含ace.js在我的顶层中html,那么事情就会起作用。但我不想这样做,因为我只想使用Angular. 但是,如果我仅使用捆绑包,那么当我运行应用程序时,我会收到以下错误 -

ace.js:1 Unable to infer path to ace from script src, use ace.config.set('basePath', 'path') to enable dynamic loading of modes and themes or with webpack use ace/webpack-resolver
f @ ace.js:1
t.loadModule @ ace.js:1
setTheme @ ace.js:1
setTheme @ ace.js:1
push../node_modules/ng2-ace-editor/src/component.js.AceEditorComponent.setTheme @ component.js:117
push../node_modules/ng2-ace-editor/src/component.js.AceEditorComponent.init @ component.js:48
push../node_modules/ng2-ace-editor/src/component.js.AceEditorComponent.ngOnInit @ component.js:40
checkAndUpdateDirectiveInline @ core.js:9250
checkAndUpdateNodeInline @ core.js:10514
checkAndUpdateNode @ core.js:10476
debugCheckAndUpdateNode @ core.js:11109
debugCheckDirectivesFn @ core.js:11069 …
Run Code Online (Sandbox Code Playgroud)

javascript angular

2
推荐指数
1
解决办法
7442
查看次数

是否有命令可以检查哪些 pod 已应用服务

我制作了一个 service.yaml 并创建了该服务。

kind: Service
apiVersion: v1
metadata:
  name: cass-operator-service
spec:
  type: LoadBalancer
  ports:
    - port: 9042
      targetPort: 9042
  selector:
    name: cass-operator
Run Code Online (Sandbox Code Playgroud)

有没有办法检查该服务已应用于哪些 Pod?

我希望使用上述服务连接到 Google Cloud 中在 external_ip/port(9042 端口)上运行 Kubernetes/Cassandra 的集群。但使用上述服务,我无法做到。

kubectl get svc节目

NAME                    TYPE           CLUSTER-IP     EXTERNAL-IP     PORT(S)          AGE
cass-operator-service   LoadBalancer   10.51.247.82   34.91.214.233   9042:31902/TCP   73s
Run Code Online (Sandbox Code Playgroud)

因此,该服务可能正在侦听 9042,但正在转发到 31902 中的 Pod。我希望两个端口均为 9042。可以这样做吗?

kubernetes

2
推荐指数
1
解决办法
3344
查看次数

Kubernetes 集群中的一个 Pod 崩溃,但其他 Pod 没有崩溃

奇怪的是,kubernetes 集群中的一个 pod 崩溃了,而另一个却没有!

codingjediweb-6d77f46b56-5mffg   0/1     CrashLoopBackOff   3          81s
codingjediweb-6d77f46b56-vcr8q   1/1     Running            0          81s
Run Code Online (Sandbox Code Playgroud)

他们都应该有相同的形象,都应该工作。可能是什么原因?

我怀疑崩溃的吊舱有旧图像,但我不知道为什么。这是因为我解决了一个问题并希望代码能够正常工作(位于其中一个 pod 上)。

不同的豆荚有可能有不同的图像吗?有没有办法检查哪个 pod 正在运行哪个映像?即使有缓存,有没有办法“刷新”旧图像或强制 K8S 下载?

更新

听了法门的建议,我看了看图。我可以看到崩溃的容器似乎正在使用现有的图像(可能是旧的)。如何让 K8S 始终拉取图像?

manuchadha25@cloudshell:~ (copper-frame-262317)$ kubectl get pods
NAME                             READY   STATUS             RESTARTS   AGE
busybox                          1/1     Running            1          2d1h
codingjediweb-6d77f46b56-5mffg   0/1     CrashLoopBackOff   10         29m
codingjediweb-6d77f46b56-vcr8q   1/1     Running            0          29m
manuchadha25@cloudshell:~ (copper-frame-262317)$ kubectl describe pod codingjediweb-6d77f46b56-vcr8q | grep image
  Normal  Pulling    29m   kubelet, gke-codingjediweb-cluste-default-pool-69be8339-wtjt  Pulling image "docker.io/manuchadha25/codingjediweb:08072020v3"
  Normal  Pulled     29m   kubelet, gke-codingjediweb-cluste-default-pool-69be8339-wtjt  Successfully pulled image "docker.io/manuchadha25/codingjediweb:08072020v3"
manuchadha25@cloudshell:~ (copper-frame-262317)$ …
Run Code Online (Sandbox Code Playgroud)

kubernetes google-kubernetes-engine

2
推荐指数
1
解决办法
106
查看次数

获取调用间谍的参数

我正在监视inemit的方法EventEmitterAngular

spyOn(answerComponent.answerEmitter, 'emit');
Run Code Online (Sandbox Code Playgroud)

我想检查是否emit带有参数调用A,但我不想检查与A. 我想检查是否emit使用值调用A.a, A.b并忽略 的值A.c

可以这样做吗?

jasmine angular-test angular6

2
推荐指数
1
解决办法
4448
查看次数