Skip to content

Commit

Permalink
docs(interop): mark forget as deprecated, mention smartview::execute
Browse files Browse the repository at this point in the history
  • Loading branch information
Curve committed Oct 31, 2024
1 parent 4cce6d5 commit ad2c381
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 13 deletions.
27 changes: 15 additions & 12 deletions docs/interoperability.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -111,17 +111,17 @@ const result = await saucer.exposed.add_ten(10);

## Calling JavaScript

You can also execute JavaScript code and capture it's result using the `evaluate` method.
You can also execute JavaScript code and capture it's result using the `evaluate` method, in case you don't need to capture the result, use `execute` instead.

```cpp
auto random = smartview.evaluate<float>("Math.random()").get();
```

You can also pass C++ objects as parameters when calling `evaluate`.
You can also pass C++ objects as parameters when calling `evaluate`/`execute`.

```cpp
auto random = smartview.evaluate<float>("Math.pow({}, {})", 2, 5).get();
smartview.evaluate<void>("console.log({})", std::vector<int>{10}).get();
smartview.execute("console.log({})", std::vector<int>{10});
```
:::tip
Expand Down Expand Up @@ -171,21 +171,24 @@ smartview.evaluate<float>("Math.random()") | saucer::then([](float result)
### Forget
:::danger
This function is deprecated since saucer v4.2.0!
In case you don't care about the result of an evaluation, use execute instead.
```cpp title="Example Usage"
smartview.execute("Math.random()");
smartview.execute("Math.pow({}, {})", 2, 5);
```
:::
<s>
Use `saucer::forget` in case you want to discard _(not use)_ the result of the evaluation.
```cpp title="Example Usage"
saucer::forget(smartview.evaluate<float>("Math.random()"));

smartview.evaluate<float>("Math.random()") | saucer::forget();
```
:::caution
A `std::future` will also block on destruction if:
> (2) the shared state is not yet ready[¹](https://en.cppreference.com/w/cpp/thread/future/%7Efuture)
As a result, most calls to `smartview.evaluate<void>(...)` should probably be forwarded to `saucer::forget` unless they originated from within an async context.
:::
</s>
### All
Expand Down
2 changes: 1 addition & 1 deletion src/components/CodeBlock.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import React, { useEffect, useState } from "react";

export function VersionedCode({ children, ...props }: Props)
{
const [version, setVersion] = useState("v4.0.0");
const [version, setVersion] = useState("v4.2.0");

useEffect(() =>
{
Expand Down

0 comments on commit ad2c381

Please sign in to comment.