使用缓冲通道,如何测量通道中有多少元素?例如,我正在创建和发送这样的频道:
send_ch := make(chan []byte, 100)
// code
send_ch <- msg
Run Code Online (Sandbox Code Playgroud)
我想衡量有多少封邮件都在通道send_ch.
我知道由于并发性,测量结果不准确,因为测量和行动之间可能会发生先发制人(例如在本视频中讨论的Google I/O 2012 - Go Concurrency Patterns).我将把它用于生产者和消费者之间的流量控制,即一旦我通过高水印,改变一些行为,直到我通过低水印回传.
我是角度5的新手,并试图在打字稿中迭代包含另一张地图的地图.如何在下面的角度下面迭代这种地图是组件的代码:
import { Component, OnInit} from '@angular/core';
@Component({
selector: 'app-map',
templateUrl: './map.component.html',
styleUrls: ['./map.component.css']
})
export class MapComponent implements OnInit {
map = new Map<String, Map<String,String>>();
map1 = new Map<String, String>();
constructor() {
}
ngOnInit() {
this.map1.set("sss","sss");
this.map1.set("aaa","sss");
this.map1.set("sass","sss");
this.map1.set("xxx","sss");
this.map1.set("ss","sss");
this.map1.forEach((value: string, key: string) => {
console.log(key, value);
});
this.map.set("yoyoy",this.map1);
}
}
Run Code Online (Sandbox Code Playgroud)
它的模板html是:
<ul>
<li *ngFor="let recipient of map.keys()">
{{recipient}}
</li>
</ul>
<div>{{map.size}}</div>
Run Code Online (Sandbox Code Playgroud)
假设我有一个功能
def x():
print(20)
Run Code Online (Sandbox Code Playgroud)
现在我想将函数分配给一个名为的变量y,这样如果我使用y它,它会x再次调用该函数.如果我只是做分配y = x(),它会返回None.
当我在订阅者中获得某个值时,我正试图返回一个observable,但我失败了.
这是代码:
canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot):Observable<boolean> {
// get route to be activated
this.routeToActivate = route.routeConfig.path;
// get user access levels
return this._firebase.isUserAdmin <-- returns Subscription, not Observable
.map(user => user.access_level)
.subscribe( access => {
// I need to return an observable here
});
}
Run Code Online (Sandbox Code Playgroud)
角度2中的可观察量资源不多,所以我不知道从哪里开始.有人可以帮忙吗?
更新 - >工作版
canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot):Observable<boolean> {
// get route to be activated
this.routeToActivate = route.routeConfig.path;
// get user access levels
return this._firebase.isUserAdmin
.map(user => {
let accessLevel = user.access_level;
if (accessLevel === …Run Code Online (Sandbox Code Playgroud) 我知道assertDictContainsSubset可以在python 2.7中做到这一点,但由于某种原因它在python 3.2中已被弃用.那么有没有办法断言一个dict包含另一个没有assertDictContainsSubset?
这看起来不太好:
for item in dic2:
self.assertIn(item, dic)
Run Code Online (Sandbox Code Playgroud)
还有其他好方法吗?谢谢
如何在模型类中使getter和setter工作?
我的目标是在输入时计算所选日期的整数值,包含日期,更新.我打算在setter中做,但Angular 4忽略了我的模型的setter和getter.
我的模特课:
export class MyModel {
@Input('date')
get date(): String {
console.log('Getting date');
...
}
set date(val) {
console.log('Setting date: ' + val);
...
}
}
Run Code Online (Sandbox Code Playgroud)
我的模板:
...
<input class="form-control" name="dp" [(ngModel)]="model.date">
...
Run Code Online (Sandbox Code Playgroud)
但是getter和setter不起作用.我错过了什么?
我已经在使用材质表单的对话框中创建了一个表单,但我似乎无法获得大于180px的输入,尽管有许多示例,包括https://material.angular.io/components/input/example.
我确定这是一个非常标准的css的东西,但我没有那种大脑,所以我无法弄清楚问题.
有没有人有一个严肃/非平凡的例子?
这是我的:
<h1 mat-dialog-title>{{title}}</h1>
<mat-dialog-content>
<form novalidate #f="ngForm" class="form-full-width">
<mat-form-field class="input-full-width">
<input type="text" [(ngModel)]="data.name" name="name" matInput placeholder="Name">
<mat-hint>Enter a unique name.</mat-hint>
</mat-form-field>
<mat-form-field class="input-full-width">
<textarea [(ngModel)]="data.description" name="description" matInput placeholder="Description"></textarea>
<mat-hint>You should describe the purpose/use of this thing.</mat-hint>
</mat-form-field>
</form>
</mat-dialog-content>
Run Code Online (Sandbox Code Playgroud)
CSS:
.form-full-width {
min-width: 150px;
max-width: 500px;
width:100%;
}
.input-full-width {
width:800px;
}
.mat-form-field.mat-form-field {
width: auto;
}
Run Code Online (Sandbox Code Playgroud)
谢谢
我有一个工厂如下,
public final class Application {
private static IFoo foo;
public static IFoo getFoo(String bar)
{
// i need to inject bar to the constructor of Foo
// obvious i have to do something, not sure what
Injector injector = Guice.createInjector();
logger = injector.getInstance(Foo.class);
return logger;
}
}
Run Code Online (Sandbox Code Playgroud)
这是Foo的定义:
class Foo
{
Foo(String bar)
{
}
}
Run Code Online (Sandbox Code Playgroud)
好.我不知道如何使用Guice将此参数传递给Foo构造函数?
有任何想法吗?
我想知道的究竟__package__是什么意思?在官方文件中没有找到任何解释,即使是在SO上.
如果你能提供一些例子,我会非常高兴.
angular ×4
python ×3
typescript ×3
python-3.x ×2
angular-cli ×1
c ×1
css ×1
go ×1
guice ×1
java ×1
networking ×1
observable ×1
python-2.7 ×1
rxjs ×1