小编Jos*_*iah的帖子

向Promise.all()添加一个Promise

我有一个api调用,有时会返回分页的响应。我想自动将这些添加到我的诺言中,以便在所有数据到达后获取回调。

这是我的尝试。我希望添加新的承诺,并在完成后解决Promise.all。

实际发生的是Promise.all不等待第二个请求。我的猜测是Promise.all在调用时会附加“侦听器”。

有没有办法“重新初始化” Promise.all()?

function testCase (urls, callback) {
    var promises = [];
    $.each(urls, function (k, v) {
        promises.push(new Promise(function(resolve, reject) {
            $.get(v, function(response) {
                if (response.meta && response.meta.next) {
                    promises.push(new Promise(function (resolve, reject) {
                        $.get(v + '&offset=' + response.meta.next, function (response) {
                            resolve(response);
                        });
                    }));
                }
                resolve(response);
            }).fail(function(e) {reject(e)});
        }));
    });

    Promise.all(promises).then(function (data) {
        var response = {resource: []};
        $.each(data, function (i, v) {
            response.resource = response.resource.concat(v.resource);
        });
        callback(response);
    }).catch(function (e) {
        console.log(e);
    });
}   
Run Code Online (Sandbox Code Playgroud)

所需的流程类似于:

  1. 创建一组承诺。
  2. 一些承诺产生更多的承诺。 …

javascript promise es6-promise

5
推荐指数
1
解决办法
5450
查看次数

发布已在运行的dotnet应用程序

我正在尝试创建一个脚本来简化发布.NET Core网站的过程.当我dotnet publish针对已经运行的服务器运行时,我遇到了一个问题.服务器是安装了dotnet捆绑包的IIS,因此IIS使用其应用程序池启动dotnet.

这是我的批处理文件.我很高兴使用其他脚本类型:

cd src/app
dotnet build --no-incremental
dotnet publish --framework netcoreapp1.0 --configuration Release --output ../../dist
Run Code Online (Sandbox Code Playgroud)

当我运行脚本时,我收到此错误:

"该进程无法访问文件'C:\ inetpub\wwwroot\app\dist\app.dll',因为它正由另一个进程使用."

这是有道理的,似乎我需要停止,部署和重启dotnet.我可以从脚本中执行此操作吗?或者我对这个问题的处理方法是错误的?

asp.net publish asp.net-core asp.net-core-1.0

4
推荐指数
1
解决办法
1974
查看次数

在 Firefox 中禁用滚轮更改数字和日期输入

这个问题类似,我试图防止滚轮形式增加数字输入。

在 Chrome/webkit 中,以下内容有效,但在 Firefox 中,滚轮仍然会更改输入。

$('input[type=number]').on('mousewheel',
    function(e){ $(this).blur(); }
);
Run Code Online (Sandbox Code Playgroud)
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<input type="number">
Run Code Online (Sandbox Code Playgroud)

html javascript css firefox jquery

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

PHP数组内存使用情况

我有一个制表符分隔的文件,我需要在一个数组(所以我可以在其中查找值).我曾经以为我可以遍历这些行并将爆炸值推送到数组中,如下所示:

error_reporting(E_ALL);
ini_set("memory_limit","20M");

$holder = array();
$csv = array();
$lines = file('Path\\To\\File\\2014_04_05_08_48.txt');

for ($a=0; $a<count($lines); $a++) {
    $csv = '';
    $csv = $lines[$a];
    $csv = explode("\t", $csv);
    array_splice($csv, 10);
    array_push($holder, $csv);
}

print_r($holder);
Run Code Online (Sandbox Code Playgroud)

该文件大约是11000行,170个字段/行(来自POS系统的当前库存的输出).该文件小于6MB.我不断收到有关超出内存限制的错误.从这里开始,我发现增加内存限制通常是一种覆盖内存泄漏/内存使用不足的方法.

我终于通过将内存限制设置为20M并在第10个值之后剥离每个数组来实现它.

我的问题是为什么我需要如此高的内存限制才能将文件内容放入数组中?超过3倍的尺寸似乎很多.难道我做错了什么?

php memory arrays tab-delimited

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

``模板语法 - 优雅的降级

新的JavaScript模板语法很棒.超级可读和强大.我想开始使用它.

我试过这个模板:

function addGalleryItem(imageData, file) { 
    try {
        var template = `
            <section class="imageGalleryItem">
                <img src="${imageData}"/>
                <div class="itemTools" id="${file.name}">
                    <input type="text" class="description" name="description" placeholder="Description"/> <br />
                    <input type="button" name="mainImage" value="Main Image" onclick="makeMain(this)"/>
                    <input type="button" name="remove" value="Remove" onclick="removeImage(this)"/>
                </div>
            </section>
        `;
    } catch { 
        var template = '<section class="imageGalleryItem">' +
            '   <img src="' + imageData + '" />' +
            '   <div class="itemTools" id="' + file.name + '">' +
            '       <input type="text" class="description" name="description" placeholder="Description"/>'+
            '       <br />' +
            '       <input type="button" …
Run Code Online (Sandbox Code Playgroud)

javascript ecmascript-6

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