我正在写一些代码来每N ms进行一次资源轮询,这会在M秒后超时.我希望尽可能多地使用Bluebird做出承诺.到目前为止,我提出的解决方案使用节点的间隔,可取消的蓝鸟承诺和蓝鸟的超时功能.
我想知道是否有更好的方法来实现蓝鸟和一般承诺的间隔时间?主要是通过确保间隔在该点停止并且永远不会无限期地继续.
var Promise = require('bluebird');
function poll() {
var interval;
return new Promise(function(resolve, reject) {
// This interval never resolves. Actual implementation could resolve.
interval = setInterval(function() {
console.log('Polling...')
}, 1000).unref();
})
.cancellable()
.catch(function(e) {
console.log('poll error:', e.name);
clearInterval(interval);
// Bubble up error
throw e;
});
}
function pollOrTimeout() {
return poll()
.then(function() {
return Promise.resolve('finished');
})
.timeout(5000)
.catch(Promise.TimeoutError, function(e) {
return Promise.resolve('timed out');
})
.catch(function(e) {
console.log('Got some other error');
throw e;
});
}
return pollOrTimeout()
.then(function(result) …Run Code Online (Sandbox Code Playgroud) 我想过滤我listView使用一个EditText盒子并使用适配器getFilter()功能.它工作得很好,直到我在文本框中放置一个空格字符.
编辑:这是一个SimpleAdapter而不是ArrayAdapter
如果我的列表中包含以下单词:{"Apple","Banana","Red Apple"}如果我输入"apple",它将返回包含苹果字样的所有项目(Apple和Red Apple).如果我输入"apple",它将不会返回任何内容.
有任何想法吗?这是代码:
searchBox = (EditText) findViewById(R.id.searchBox);
searchBox.addTextChangedListener(filterTextWatcher);
Run Code Online (Sandbox Code Playgroud)
和
private TextWatcher filterTextWatcher = new TextWatcher() {
public void onTextChanged(CharSequence s, int start, int before, int count) {
// TODO Auto-generated method stub
}
public void beforeTextChanged(CharSequence s, int start, int count,
int after) {
// TODO Auto-generated method stub
}
public void afterTextChanged(Editable s) {
// TODO Auto-generated method stub
myAdapter.getFilter().filter(s.toString());
}
};
Run Code Online (Sandbox Code Playgroud) 尝试通过SSL连接到Imgur API会给我一个错误.这是代码和错误:
API_URI = URI.parse('https://api.imgur.com')
API_PUBLIC_KEY = 'Client-ID --'
ENDPOINTS = {
:image => '/3/image',
:gallery => '/3/gallery'
}
# Public: Upload an image
#
# args - The image path for the image to upload
#
def upload(image_path)
http = Net::HTTP.new(API_URI.host)
http.use_ssl = true
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
params = {'image' => File.open(image_path)}
request = Net::HTTP::Post.new(API_URI.request_uri)
request.set_form_data(params)
request.add_field('Authorization', API_PUBLIC_KEY)
response = http.request(request)
puts response.body
end
Run Code Online (Sandbox Code Playgroud)
而错误:
`connect': SSL_connect returned=1 errno=0 state=SSLv2/v3 read server hello A: unknown protocol (OpenSSL::SSL::SSLError)
Run Code Online (Sandbox Code Playgroud)
我知道VERIFY_NODE不是很好的做法,但我现在只想测试连接.
Ruby版本:1.9.2
我正在做一个 perl 脚本,我需要从命令行获取多个值。例子:
perl script.pl --arg1 op1 op2 op3
Run Code Online (Sandbox Code Playgroud)
我正在使用 Getopt::Long 并且可以让它工作:
perl script.pl --arg1 op1 --arg1 op2 --arg1 op3
Run Code Online (Sandbox Code Playgroud)
但我真的需要(想要)第一个选择。
我检查了他们的文档,这应该是我想要的:
GetOptions('arg1=s{3}' => \@myArray);
Run Code Online (Sandbox Code Playgroud)
http://search.cpan.org/~jv/Getopt-Long-2.38/lib/Getopt/Long.pm#Options_with_multiple_values
但我收到这个错误:
选项规范错误:“arg1=f{3}”
有什么想法/解决方案吗?
如何在变量中转义引号以与另一个变量进行比较.
示例:脚本输出"test.exe"的输出"正常"(没有周围的引号)
在批处理脚本中,我将输出保存在我的批处理脚本中的变量中,然后想要与保存的变量进行比较.
set ouputTest1 = "The output of "test.exe" is OK"
test.exe -p 75 > temp.txt
set /p TESTOUTPUT=< temp.txt
if %TESTOUTPUT% == %ouputTest1%
Run Code Online (Sandbox Code Playgroud)
问题在于outputTest1变量和字符串中的引号.我尝试使用这样的双引号:
set ouputTest1 = "The output of ""test.exe"" is OK"
Run Code Online (Sandbox Code Playgroud)
但没有运气.
有任何想法吗?