-
Notifications
You must be signed in to change notification settings - Fork 90
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
K2: add support for asynchronous callbacks (#1103)
Also, this commit adds array_map implementation that supports both sync and async functors
- Loading branch information
Showing
7 changed files
with
106 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
<?php | ||
|
||
/** @kphp-extern-func-info interruptible */ | ||
function array_map (callable(^2[*] $x):any $callback, $a ::: array) ::: ^1() []; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
<?php | ||
|
||
require_once __DIR__ . '/array.txt'; | ||
require_once __DIR__ . '/job-workers.txt'; | ||
|
||
define('TODO', -1); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<?php | ||
|
||
$async_func_str = "async function result"; | ||
$sync_func_str = "sync function result"; | ||
|
||
/** @kphp-required */ | ||
function async_func(string $str): string { | ||
sched_yield_sleep(0.005); | ||
global $async_func_str; | ||
return $async_func_str; | ||
} | ||
|
||
/** @kphp-required */ | ||
function sync_func(string $str): string { | ||
global $sync_func_str; | ||
return $sync_func_str; | ||
} | ||
|
||
$arr = ["1", "2", "3"]; | ||
|
||
foreach (array_map('async_func', $arr) as $elem) { | ||
if ($elem != $async_func_str) { | ||
critical_error("error"); | ||
} | ||
} | ||
|
||
foreach (array_map('sync_func', $arr) as $elem) { | ||
if ($elem != $sync_func_str) { | ||
critical_error("error"); | ||
} | ||
} |