thekid/rfc — Issue #81: RFC 0081: Runnable interface 
Author: thekid
Created: 2011-10-09 14:56:15+00:00
State: open
Labels: implemented, rfc

Scope of Change
====
An interface "Runnable" will be added to the lang package. The class
lang.Thread will implement this interface.

Rationale
====
Create easy closure-like anonymous classes in conjunction with newinstance().

Functionality
====

Interface lang.Runnable declaration
----

```php

```

Shutdown hooks
----

```php
transaction= $transaction;
}
public function run() {
$this->transaction->isOpen() && $this->transaction->rollback();
}
}'));
?>
```

Example
----

```php
finalizer= $finalizer;
}

function doWork($payload) {
// ...TODO...
}

function process($payload) {
try {
$this->doWork($payload);
} catch (Throwable $e) {
$e->printStackTrace();
} finally(); {
$this->finalizer->run();
if ($e) throw($e);
}
}
}

$p= new Processor(newinstance('lang.Runnable', array(), '{
public function run() { Console::writeLine('Done!'); }
}'));
$p->process($payload);
?>
```

Security considerations
====
n/a

Speed impact
====
Makes lang.Thread a little bit slower.

Dependencies
====
- xp-framework/rfc #80 ("Anonymous class creation")

Related documents
====
- http://java.sun.com/j2se/1.5.0/docs/api/java/lang/Runnable.html
Java Runnable interface

Comments
====