Skip to content
This repository has been archived by the owner on Dec 16, 2019. It is now read-only.

Promise not working with Thread #283

Closed
ShawnXu opened this issue Mar 31, 2014 · 3 comments
Closed

Promise not working with Thread #283

ShawnXu opened this issue Mar 31, 2014 · 3 comments

Comments

@ShawnXu
Copy link

ShawnXu commented Mar 31, 2014

Using this promise library with composer

{
  "require": {
    "react/promise": "1.0"
  }
}

Test code

<?php

require 'vendor/autoload.php';

class DeferredWorker extends Thread
{
    protected $deferred = null;
    public $promise = null;

    public function __construct() {
        $this->deferred = new React\Promise\Deferred();
        $this->promise = $this->deferred->promise();
    }
}

class Worker1 extends DeferredWorker
{
  public function run() {
    sleep(1);
    $this->deferred->resolve("worker 1");
  }
}

$w1 = new Worker1();
$w1->promise->then(function ($value) {
    echo $value; // not called, yet no ERROR
});
$w1->start();

The code seems normal to me; think it's a straight forward way to do async tasks in javascript. I'm wondering what I'm missing to do promises properly in PHP with pThread?

Thanks,
Shawn

@krakjoe
Copy link
Owner

krakjoe commented Mar 31, 2014

http://github.com/krakjoe/promises

React doesn't yet have a mode compatible with pthreads, afaik, it's being worked on ...

Not much I can do about this, so closing the bug since it's not actually a bug in pthreads ;)

@krakjoe krakjoe closed this as completed Mar 31, 2014
@ShawnXu
Copy link
Author

ShawnXu commented Mar 31, 2014

Sorry for the noise. I wonder if there's a pthread ready promise library that you are aware of and would recommand. Thanks.

@krakjoe
Copy link
Owner

krakjoe commented Mar 31, 2014

I linked to the one I wrote, here's composer page for it ... https://packagist.org/packages/krakjoe/promises

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants