小编use*_*319的帖子

如何删除关联的操作?

学习iOS开发,按照Apple网站上的教程进行操作。在我将按钮连接到视图控制器代码(通过ctl-drag)后,我决定重命名该操作。我没有进行重构,而是删除了代码部分并重新连接(通过 ctl 拖动)。现在,每次我尝试运行该应用程序时,它都会崩溃,因为它仍在寻找旧的操作。

如何解决这种情况而不是创建新项目?

我正在使用 Xcode 9。

xcode

4
推荐指数
2
解决办法
3915
查看次数

Node.js 数组切片操作是“线程安全的”吗?

我有一个简单的 websocket 聊天服务器,可以处理多个客户端。我使用一个数组来跟踪所有客户端,并在客户端关闭连接时对数组进行切片。

我想知道当多个客户端大约同时关闭连接时,对数组进行切片是否会导致问题。

这是代码段:

var clients = []; 
var wsServer = new webSocketServer ({
    httpServer: httpserver
});

wsServer.on('request', function(request) {
    var connection = request.accept(null, request.origin);
    var index = clients.push(connection) - 1;

....

connection.on('close', function(connection) {
    for (var i=0; i<clients.length; i++) 
        if (i != index) clients[i].sendUTF('Some client has left the chat!');

    //At this point some other clients may have disconnected and the above 
    //for-loop may be running for another connection.

   clients.splice(index, 1);

   //After the array has been sliced, will the …
Run Code Online (Sandbox Code Playgroud)

websocket node.js

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

标签 统计

node.js ×1

websocket ×1

xcode ×1