我有承诺需要同步的对象.例如,第二个承诺在第一个承诺完成之前不应该起作用.如果第一个拒绝,则必须再次执行.
我已经实现了一些例子.这个很好用.调用getVal,等待2000ms,返回,i ++,再次调用getVal .....
getVal() {
return new Promise(function(resolve, reject) {
setTimeout(function(){ resolve(19) }, 2000);
});
}
async promiseController(){
for(var i =0;i<5;i++)
{
var _val = await this.getVal()
console.log(_val+'prom');
}
}
Run Code Online (Sandbox Code Playgroud)
但我需要控制一组promise对象.我想要做的是我有一个数据,我把它分成5块.在处理完第一部分(例如:发送到服务器)后,我想要处理第二部分,否则我必须再次处理第一部分.
这是我制作的原型实现
getVal() {
return new Promise(function(resolve, reject) {
setTimeout(function(){ resolve(19) }, 2000);
});
}
async promiseController(){
var proms=[]
for(var i =0;i<5;i++)
{
proms.push(this.getVal())
}
for(var i =0;i<5;i++)
{
var _val = await proms[i]
console.log(_val+'prom');
}
}
Run Code Online (Sandbox Code Playgroud)
此代码中的Promises对象按顺序工作.我如何修复下面的代码,以便它作为第一个例子同步工作.
我正在测试一部较旧的iPhone,我必须像疯子一样摇动手机才能进入开发菜单.是否有可以通过网桥发送的命令重新加载或启动开发菜单?我知道现场重装,但这不是我想要的.
例如,在我的Android设备上,我可以发送adb shell input keyevent 82模拟摇动事件并调出开发菜单.
我是这个主题的新手.我只是想连接我的数据库并获取数据.当使用静态连接时,它正在工作但不使用非静态.正如我所说,我对Php知之甚少,可能会遗漏一些简单的东西.尝试获取非静态时出错由于发生内部服务器错误,无法显示页面.我的代码
> <?php
class DB_Connect extends mysqli{
// protected static $connection;//working
protected $connection; / not working
function __construct() {
}
function __destruct() {
}
public function connect() {
if(!isset($this->$connection)) {
$config = parse_ini_file('./configOop.ini');
$this->$connection = new mysqli($config['dbhost'],$config['username'],$config['password'],$config['dbname']);
}
else{}
return $this->$connection;
/*
// using this part for static connection object, working
if(!isset(self::$connection)) {
$config = parse_ini_file('./configOop.ini');
self::$connection = new mysqli($config['dbhost'],$config['username'],$config['password'],$config['dbname']);
}
else{}
return self::$connection;
*/
}
// Closing database connection
public function close() {
// mysql_close();
}
}
?>
Run Code Online (Sandbox Code Playgroud)
// …
我正在编写一个react-native组件,我使用的是事件,但是当我发送事件时,我的本机模块不会构建在旧版本的反应上 bridge.eventDispatcher..
那么有没有办法检查版本在react和react-native模块实现之间切换?谢谢.