我听过 'SIGTERM' 信号进行正常关闭:
// snippet of server.js
process.on('SIGTERM', () => {
console.log('I will close database here.')
process.exit(0)
})
Run Code Online (Sandbox Code Playgroud)
我使用 Jest 进行测试,代码如下:
describe('on SIGTERM', () => {
beforeAll(() => {
process.exit = jest.fn(); // substituted by mock function
return require('../server'); // run server.js
});
it('should exit with code 0', async () => {
process.kill(process.pid, 'SIGTERM'); // the code killed my jest process immediately
expect(process.exit).toHaveBeenCalledWith(0);
})
})
Run Code Online (Sandbox Code Playgroud)
这是下面的错误消息:
npm 运行测试:服务器服务器/测试/server.spec.js
错误 命令失败,退出代码 143。
我确信 process.exit 被模拟函数替换了,因为我曾尝试调用 process.exit(0),该进程保持活动状态。但是 process.kill 立即杀死了我的进程。
为什么会发生这种情况? …
// function 1------- Currying
func increment (incrementBy x: Int)(y: Int) -> Int {
return x + y
}
// function 2------- The function that return a function
func increment(incrementBy x: Int) -> ((Int) ->Int){
func incrementFunc(y: Int){
return x + y
}
}
Run Code Online (Sandbox Code Playgroud)
这两个功能是否做同样的事情,不是吗?我可以用同样的方式使用它们.像这样:
let incrementFunc = increment(incrementBy: 10)
var number = 10
number = incrementFunc(number)
Run Code Online (Sandbox Code Playgroud)
所以,我很困惑,他们有什么区别?每种方式的优点是什么?
步骤 1:\n我声明了一个协议,名为ARDevice:
protocol ARDevice {\n var deviceName:String{get}\n}\nRun Code Online (Sandbox Code Playgroud)\n\n步骤2:\n然后我用它来扩展NSNetService\xef\xbc\x9a
extension NSNetService:ARDevice{\n var deviceName:String{\n get{\n return self.name\n }\n }\n}\nRun Code Online (Sandbox Code Playgroud)\n\n第三步:我创建了一个数组:
\n\nvar deviceList = [ARDevice]()\nRun Code Online (Sandbox Code Playgroud)\n\n第 4 步:我想在回调方法中使用contains(:),但不能:\n
我该怎么做?\n我必须实施任何协议吗?
\n我想设置我的http服务器的静态目录,并在其中放一些图片,以便用户可以使用url获取我的图片。但我失败了,下面的代码不起作用:
# ????
STATIC_DIRNAME = "resources"
# ??static path
settings = {
"static_path": os.path.join(os.path.dirname(__file__), STATIC_DIRNAME),
}
# and I passed settings to Application
app = tornado.web.Application([
(r"/pictures", handler.PicturesHandler),
], **settings)
Run Code Online (Sandbox Code Playgroud)
如何将静态目录设置为“资源”?
(我想通过如URL,让我的图片:localhost:8888/resources/1.jpg)
我想做一些事情,在控制器的initialize()方法完成后,但在场景show之前.在场景显示之前是否会调用任何方法?我想在方法中加入一些代码.
FXMLLoader loader = new FXMLLoader();
loader.setLocation(getClass().getResource("sample.fxml"));
AnchorPane pane = loader.load();
Scene gameScene = new Scene(pane);
//I load a secne above,the I will get the controller,set some properties,then,use the properties to read a file before the secene show.
GameUIController controller = loader.getController();
controller.setGameFileLoacation("game1.txt");//I set a property here.I want to use it to read game file,and load game,set some necessary UI.
primaryStage.setScene(gameScene);//this tow statement will show the scene.
primaryStage.show();
Run Code Online (Sandbox Code Playgroud)
我无法将代码放入initialize()方法,因为它会在fxml文件加载时调用(当我还没有得到控制器时).那么,我该怎么办?
非常感谢 !
我为按钮设置了工具提示,但是它看起来太小(字体大小),我怎么可以将其放大?我试过了myTooltip.setFont(new Font(20)),但是为什么不起作用,为什么?如何使字体变大?谢谢大家!
public void startApp(){
primaryStage.show();
new Thread(new Runnable(){
public void run(){
Thread.sleep(20000);//2 seconds
//do something.........
System.out.println("all things done");
}
}).run();
}
Run Code Online (Sandbox Code Playgroud)
我认为primaryStage将首先显示.但事实上,在新线程完成之后(在打印完所有事情之后),primaryStage始终显示.如果我删除'Thread.sleep(20000)',那么在所有事情完成之后,primaryStage也会被删除.为什么?我错了吗?先谢谢大家!