示例#1
0
 /**
  * @memcheck
  */
 public function testPromiseThen()
 {
     $this->data["var"] = "x";
     $promise = new ResolvablePromise(function ($x) {
         return $x + 10;
     });
     $seq2 = new Sequence(function ($x) {
         return $x + 100;
     });
     $seq2->then(function ($x) {
         $this->data[$this->data["var"]] = $x;
     });
     $promise->then($seq2);
     $promise->done(1);
     $this->data["var"] = "y";
     $seq2(2);
     $this->assertEquals(["var" => "y", "x" => 111, "y" => 102], $this->data);
 }
示例#2
0
 /**
  * @memcheck
  */
 public function testForgetNamed()
 {
     $promise1 = new ResolvablePromise(function () {
         $this->data["promise.1"] = true;
     });
     $promise2 = new Promise(function () {
         $this->data["promise.2"] = true;
     });
     $promise2->setName("promise2");
     $promise3 = new Promise(function () {
         $this->data["promise.3"] = true;
     });
     $promise3->setName("promise3");
     $promise1->then($promise2);
     $promise1->forget("promise3");
     $promise1->forget("promise2");
     $promise1->done(null);
     $this->assertSame(["promise.1" => true], $this->data);
 }