我有一个看起来如下的未来函数,其中this._executing.set()
在数据库集合中设置一个值:
Cylon._send = function (command) {
let future = new Future();
this._executing.set(true);
// ... waits for an "okay" on `commands` socket before resolving.
future.resolve(() => this._executing.set(false));
return future;
}.future();
我有另一种方法可以使用其中两种方法。
Cylon.executeSubroutine = function (subroutine, expression) {
let execFuture = new Future();
let commandFuture = this._send(`XQ#${subroutine}`);
commandFuture.resolve(() => this._executing.set(true)));
execFuture.resolve(() => this._executing.set(false));
// execFuture waits on `expression` on `messages` socket before resolving.
Future.wait(commandFuture, execFuture);
}
当我记录状态时,它会执行以下操作。
executing set to true executing set to true executing set to false executing set to false
为什么这样做?我想回调是按照不正确的顺序设置的,但我不确定如何正确地做到这一点。