Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 5 additions & 11 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,12 @@ jobs:
strategy:
fail-fast: false
matrix:
php: ['8.2', '8.3', '8.4']
php: ['8.2', '8.3', '8.4', '8.5']

steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Unset local path repositories
run: composer config --unset repositories

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
Expand Down Expand Up @@ -53,8 +50,8 @@ jobs:
strategy:
fail-fast: false
matrix:
php: ['8.2', '8.3', '8.4']
php: ['8.2', '8.3', '8.4', '8.5']

steps:
- name: Checkout code
uses: actions/checkout@v4
Expand All @@ -76,15 +73,12 @@ jobs:
strategy:
fail-fast: false
matrix:
php: ['8.2', '8.3', '8.4']
php: ['8.2', '8.3', '8.4', '8.5']

steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Unset local path repositories
run: composer config --unset repositories

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
Expand All @@ -105,4 +99,4 @@ jobs:
run: composer install --prefer-dist --no-progress

- name: Run PHPStan
run: composer phpstan
run: composer phpstan
59 changes: 38 additions & 21 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,32 +49,48 @@ $chained = $effect->flatMap(function($content) {
});
```

### IOApp
### Async Execution with start()

`IOApp` provides a way to run your IO programs. It's the entry point for your effectful applications.
The `start()` method allows you to fork computations into background fibers, enabling fire-and-forget patterns:

```php
use Phunkie\Effect\Functions\io\io;
use Phunkie\Effect\IO\IO;
use Phunkie\Effect\IO\IOApp;

class MyApp extends IOApp
{
public function run(): IO
{
return io(function() {
echo "Hello, Effects!";
return 0;
use function Phunkie\Effect\Functions\io\io;

// Define an async operation
$sendEmail = io(function() use ($user) {
mail($user->email, 'Welcome!', '...');
return 'sent';
});

// Fork to background and continue immediately
$program = $sendEmail
->start() // Returns IO<AsyncHandle<string>>
->map(function($handle) {
// Continue with other work...
return 'Email queued';
});

// Or await the result later
$program = $sendEmail
->start()
->flatMap(function($handle) {
// Do other work here...
$otherWork = io(fn() => 'other work done');

return $otherWork->map(function($result) use ($handle) {
// Now wait for email to finish
$emailResult = $handle->await();
return [$result, $emailResult];
});
}
}
```
});

To run your application, use the Phunkie console:
// Custom execution context
use Phunkie\Effect\Concurrent\ParallelExecutionContext;

```bash
$ bin/phunkie MyApp
Hello, Effects!
$heavyComputation = io(fn() => processLargeDataset());
$handle = $heavyComputation
->start(new ParallelExecutionContext()) // Use parallel threads
->unsafeRun();
```

## Features
Expand All @@ -84,7 +100,8 @@ Hello, Effects!
- Composable effect chains
- Error handling through Either
- Resource management
- Concurrency support (coming soon)
- **Async execution with `start()`** - Fork computations to background fibers
- **Custom execution contexts** - Control how effects are executed

## Why Phunkie Effects?

Expand Down
6 changes: 3 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
}
],
"require": {
"php": "^8.2 || ^8.3 || ^8.4",
"phunkie/phunkie": "^1.0"
"php": "^8.2 || ^8.3 || ^8.4 || ^8.5",
"phunkie/phunkie": "^1.1.0"
},
"require-dev": {
"phpunit/phpunit": "^10.5",
Expand Down Expand Up @@ -54,4 +54,4 @@
"config": {
"bin-dir": "bin"
}
}
}
Loading