Skip to content

Instantly share code, notes, and snippets.

@Danack
Created May 10, 2013 18:47
Show Gist options
  • Save Danack/5556517 to your computer and use it in GitHub Desktop.
Save Danack/5556517 to your computer and use it in GitHub Desktop.
Co-routines can be done as objects instead.
<?php
function loggerCoroutine(){
// set something up
$fileHandle = fopen($fileName, 'a');
while($continue == true){
//Do something
fwrite($fileHandle, yield . "\n");
}
//close everything down
fclose($fileHandle);
}
class Logger{
private $fileHandle;
function __construct(){
// set something up
$this->fileHandle = fopen($fileName, 'a');
}
function write($line){
//Do something
fwrite($this->fileHandle, yield . "\n");
}
function close(){
//close everything down
fclose($this->fileHandle);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment