Skip to content

Commit 80c955a

Browse files
committed
Add data api timeout
1 parent 8c9bcfe commit 80c955a

1 file changed

Lines changed: 45 additions & 3 deletions

File tree

Writerside/topics/webview/data-api.md

Lines changed: 45 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,11 +52,28 @@ $app = new Boson\Application();
5252

5353
var_dump($app->webview->data->get('document.location'));
5454
//
55-
// Boson\WebView\Api\DataApi\Exception\UnprocessableRequestException:
56-
// Request "document.location" could not be processed
57-
// because application is not running
55+
// Boson\WebView\Api\Data\Exception\ApplicationNotRunningException:
56+
// Request "document.location" could not be processed
57+
// because application is not running
5858
//
5959
</code-block>
60+
61+
If the page is currently loading, synchronous requests are also unavailable.
62+
63+
<code-block lang="php">
64+
$app = new Boson\Application();
65+
66+
$app->on(function(Boson\WebView\Event\WebViewNavigating $e) {
67+
var_dump($e->subject->data->get('document.location'));
68+
//
69+
// Boson\WebView\Api\Data\Exception\WebViewIsNotReadyException:
70+
// Request "document.location" could not be processed
71+
// because webview is in navigating state
72+
//
73+
});
74+
75+
$app->webview->url = 'https://example.com';
76+
</code-block>
6077
</warning>
6178

6279
<note>
@@ -86,6 +103,31 @@ be used to simplify the examples.
86103

87104
</note>
88105

106+
### Synchronous Access Timeout
107+
108+
Note that synchronous access is instant in most cases, but can sometimes
109+
cause timeout errors and call termination.
110+
111+
For example, if you try to use a deferred call, receiving it synchronously
112+
```php
113+
$app->webview->get('fetch("https://very-slow-client/request.json")');
114+
//
115+
// Boson\WebView\Api\Data\Exception\StalledRequestException:
116+
// Request "fetch(\"https://very-slow-client/request.json\")"
117+
// is stalled after 0.10s of waiting
118+
//
119+
```
120+
121+
Timeout of 0.1s is the default value, which can be changed
122+
globally in the settings.
123+
124+
If you are sure that a long query is acceptable, you can set other limits
125+
on the query explicitly by passing the timeout (in seconds) as the
126+
second argument.
127+
128+
```php
129+
$result = $app->webview->get('very_long_function()', timeout: \INF);
130+
```
89131

90132
## Async Access
91133

0 commit comments

Comments
 (0)