我正在使用Node v6.2.2和Electron v1.2.5.
我有一个小的应用程序,我已经建立在Electron之上,现在我需要fork
在另一个节点进程中运行一些长时间运行的任务,但它似乎不起作用,当我正在查看ChildProcess
我可以的对象时看到在参数spawnargs [0]初始化与电子可执行文件而不是节点,所以我做的是我试图使用spawn
相反,但它没有尽我所能.
这是我用于spawn
进程的代码(存在于文件中./modules/tester.js
):
const {spawn} = require('child_process');
var child = spawn("node", ["worker.js"], { stdio: ['inherit', 'inherit', 'inherit', 'ipc'] });
const self = {};
self.start = () => {
console.log("start");
child.send("ping");
};
Run Code Online (Sandbox Code Playgroud)
这是我用于我的worker.js
文件的代码:
process.on("message", (data) => {
console.log(data);
console.log("pong");
});
Run Code Online (Sandbox Code Playgroud)
最后这就是我消耗它的方式.
const {app} = require("electron");
const tester = require("./modules/tester");
app.on("ready", () => {
tester.start();
});
Run Code Online (Sandbox Code Playgroud)
也许我做错了但是我不这么认为,因为当我使用nodejs它似乎工作得很好.
我尝试了很多例子但是它们似乎都不起作用,另一种可能性是我需要在Electron中做一些特别的工作,但是我不知道.
我对服务器/客户端架构有以下要求:
编写一个异步工作的服务器/客户端。
通信需要是双工的,即两端都可以读和写。
多个客户端可以在任何给定时间连接到服务器。
服务器/客户端应该等待,直到它们可用并最终建立连接。
一旦客户端连接,它应该写入流。
然后服务器应该从流中读取并将响应写回客户端。
最后,客户端应该读取响应并且通信应该结束。
因此,考虑到以下要求,我编写了以下代码,但我不太确定它,因为管道的文档有些缺乏,不幸的是,代码似乎无法正常工作,它在某个点挂起。
namespace PipesAsyncAwait471
{
using System;
using System.Collections.Generic;
using System.IO.Pipes;
using System.Linq;
using System.Threading.Tasks;
internal class Program
{
private static async Task Main()
{
List<Task> tasks = new List<Task> {
HandleRequestAsync(),
};
tasks.AddRange(Enumerable.Range(0, 10).Select(i => SendRequestAsync(i, 0, 5)));
await Task.WhenAll(tasks);
}
private static async Task HandleRequestAsync()
{
using (NamedPipeServerStream server = new NamedPipeServerStream("MyPipe",
PipeDirection.InOut,
NamedPipeServerStream.MaxAllowedServerInstances,
PipeTransmissionMode.Message,
PipeOptions.Asynchronous))
{
Console.WriteLine("Waiting...");
await server.WaitForConnectionAsync().ConfigureAwait(false);
if (server.IsConnected)
{
Console.WriteLine("Connected");
if (server.CanRead) {
// Read something...
} …
Run Code Online (Sandbox Code Playgroud) 我正在开发一个支持外部插件的ASP.NET MVC项目,现在,我正在从Unity转移到Autofac,我需要包装Autofac的生命周期对象,以便插件不必在Unity I中引用它可以做点什么.
public sealed class UnityScopeFactory : IDependencyScopeFactory
{
private HttpRequestScope _httpRequest;
private SingletonScope _singleton;
private TransientScope _transient;
public IDependencyScope HttpRequest()
{
return _httpRequest ?? (_httpRequest = new HttpRequestScope());
}
public IDependencyScope Singleton()
{
return _singleton ?? (_singleton = new SingletonScope());
}
public IDependencyScope Transient()
{
return _transient ?? (_transient = new TransientScope());
}
private class HttpRequestScope : IDependencyScope
{
public object CreateScope()
{
return new HttpPerRequestLifetimeManager();
}
}
private class SingletonScope : IDependencyScope
{
public object CreateScope()
{ …
Run Code Online (Sandbox Code Playgroud) 在发布模式下编译时出现以下错误.
1>d:\users\eyal\projects\code\yalla\core\src\runbox\win32\window.cpp : fatal error C1001: An internal error has occurred in the compiler.
1> (compiler file 'f:\dd\vctools\compiler\utc\src\p2\main.c', line 249)
1> To work around this problem, try simplifying or changing the program near the locations listed above.
1> Please choose the Technical Support command on the Visual C++
1> Help menu, or open the Technical Support help file for more information
1> link!RaiseException()+0x48
1> link!CxxThrowException()+0x65
1> link!std::_Xout_of_range()+0x1f
1> link!InvokeCompilerPass()+0x1b4e2
1> link!InvokeCompilerPass()+0x22efe
1> link!InvokeCompilerPass()+0x2332e
1> link!InvokeCompilerPass()+0x232f9
1> link!InvokeCompilerPass()+0x233cb
1> link!InvokeCompilerPass()+0x22b04
1> …
Run Code Online (Sandbox Code Playgroud) 我正在开发一个项目,我有一些递归数据结构,我想为它创建一个夹具.
数据结构是XmlCommandElement
,它有一个ToCommand
转换XmlCommandElement
为的方法Command
.
树上的每个节点可以是a XmlCommandElement
和/或XmlCommandPropertyElement
.
现在,为了测试ToCommand
我想XmlCommandElement
用一些任意数据获取的方法的行为.
我想控制树的深度XmlCommandElement
和XmlCommandPropertyElement
节点和/或每个节点的实例数量.
所以这是我用于灯具的代码:
public class XmlCommandElementFixture : ICustomization
{
private static readonly Fixture _fixture = new Fixture();
private XmlCommandElement _xmlCommandElement;
public int MaxCommandsPerDepth { get; set; }
public int MaxDepth { get; set; }
public int MaxPropertiesPerCommand { get; set; }
public XmlCommandElementFixture BuildCommandTree()
{
_xmlCommandElement = new XmlCommandElement();
var tree = new Stack<XmlCommandElementNode>();
tree.Push(new XmlCommandElementNode(0, _xmlCommandElement)); …
Run Code Online (Sandbox Code Playgroud) 我想弄清楚几个小时,我想这与我配置错误的requirejs文件('test.main.js')有关,但我不太确定,有人可以向我解释有什么问题吗?
如果您需要我提供更多信息,我很乐意提供.
这是堆栈跟踪的输出.
Eyal Shilony@LIONKING /d/Projects/Code/Development/tsToolkit
$ ./karma.sh start
INFO [karma]: Karma v0.12.16 server started at http://localhost:8380/
INFO [IE 11.0.0 (Windows 7)]: Connected on socket GCSNAkUAY24F-MN7dkGQ with id manual-4464
IE 11.0.0 (Windows 7) ERROR: 'There is no timestamp for /base/src/tests/core/types.tests!'
WARN [web-server]: 404: /base/src/tests/core/types.tests
IE 11.0.0 (Windows 7) ERROR
Script error for: /base/src/tests/core/types.tests
http://requirejs.org/docs/errors.html#scripterror
at D:/Projects/Code/Development/tsToolkit/node_modules/requirejs/require.js:141
Run Code Online (Sandbox Code Playgroud)
这是我正在使用atm的目录结构.
.
|-- WebEssentials-Settings.json
|-- jake.sh
|-- jakefile.js
|-- karma.sh
|-- node_modules
| |-- jake
| | |-- Jakefile
| | |-- Makefile
| …
Run Code Online (Sandbox Code Playgroud) 我正在使用AutoFixture,我想使用特定的构造函数.
我有以下代码,我喜欢用ITemplateParameterHandler选择构造函数.
public sealed class TemplateSegmentHandler : ITemplateSegmentHandler
{
public TemplateSegmentHandler(ITemplateIterator iterator)
: this(new TemplateParameterHandler(iterator))
{
Contract.Requires(iterator != null);
}
public TemplateSegmentHandler(ITemplateParameterHandler parameterHandler)
{
Contract.Requires(parameterHandler != null);
_parameterHandler = parameterHandler;
_parameterHandler.Ending += EndingParameter;
}
// ...
}
Run Code Online (Sandbox Code Playgroud)
编辑:
我想注入以下假实现.(我正在使用NSubstitute来创建虚假对象.)
public sealed class CustomTemplateParameter : ICustomization
{
private readonly ITemplateParameterHandler _context;
public CustomTemplateParameter()
{
_context = Substitute.For<ITemplateParameterHandler>();
}
public void Customize(IFixture fixture)
{
fixture.Customize<ITemplateParameterHandler>(c => c.FromFactory(() => _context));
}
public CustomTemplateParameter SetCatchAll(bool isCatchAll)
{
_context.IsCatchAll.Returns(isCatchAll);
return this;
}
}
Run Code Online (Sandbox Code Playgroud)
这是我尝试使用它的方式.
[Fact] …
Run Code Online (Sandbox Code Playgroud) 我已经通过 Vue-CLI v3.0.0-beta.15 创建了一个 Vue 项目,现在,一切正常,我的意思是,当我npm run serve
编译并运行良好时,TypeScript 会抛出以下错误消息,并且仅在编辑器内部!
Experimental support for decorators is a feature that is subject to change in a future release. Set the 'experimentalDecorators' option to remove this warning.
Run Code Online (Sandbox Code Playgroud)
我尝试过但没有奏效的事情:
我仔细检查experimentalDecorators
我的tsconfig.json
文件中 Vue 默认设置为 true 。
我尝试jsconfig.json
使用以下选项创建一个文件:
{
"compilerOptions": {
"experimentalDecorators": true
}
}
Run Code Online (Sandbox Code Playgroud)我试图在 VSCode 中更改以下选项 "javascript.implicitProjectConfig.experimentalDecorators": true
现在,我正在使用带有 VSCode 的 Vetur 扩展,我已经在他们的 repo 上发布了一个问题,但我没有在 Visual Studio for Vue 中使用任何扩展,但我得到了同样的错误,所以我不知道是什么触发了它,但是我认为有些东西没有选择tsconfig.json
文件。
以下是我为生成项目而采取的步骤: …
我正在使用AngleSharp解析HTML5,我正在做的是用一些HTML包装我想要解析的元素,使其成为有效的HTML5然后使用解析器,是否有更好的做法它?意思是,直接解析特定元素并验证结构确实是HTML5?
我正在尝试使用Node和Bluebird(promises库)递归迭代一个给定的目录,但只要看起来它不能正常工作.
当我取消注释下面的'console.log'行时,似乎我得到了正确的结果,但我不确定是怎么回事,因为我从下面的消费代码得到的最终结果只是第一个文件第一个目录.
也许问题不在于迭代函数本身,而在于我正在消费它的方式.
我对承诺有点新意,所以也许我只是以错误的方式接近它.
这是我写的代码.
import * as Path from "path";
import * as Promise from "bluebird";
const FS: any = Promise.promisifyAll<any>((require("fs")));
export class Dir {
public static iterate(path: string) {
return new Promise((resolve, reject) => {
FS.lstatAsync(path).then(stat => {
if (stat.isDirectory()) {
FS.readdirAsync(path).each(name => {
let fullPath = Path.join(path, name);
// console.log(fullPath);
FS.lstatAsync(fullPath).then(stat => stat.isDirectory() ? Dir.iterate(fullPath) : resolve(fullPath));
});
} else {
reject(`The path '${path}' is not a directory.`)
}
});
})
}
}
Run Code Online (Sandbox Code Playgroud)
这是我使用/消费它的方式
Dir.iterate(ProjectPaths.client) …
Run Code Online (Sandbox Code Playgroud) c# ×3
.net ×2
autofixture ×2
typescript ×2
anglesharp ×1
asp.net-mvc ×1
autofac ×1
bluebird ×1
c++ ×1
c1001 ×1
electron ×1
html5 ×1
javascript ×1
karma-runner ×1
lifetime ×1
named-pipes ×1
node.js ×1
parsing ×1
promise ×1
recursion ×1
requirejs ×1
unique-ptr ×1
unit-testing ×1
vetur ×1
vue.js ×1