From ad2c381c15e434c895ed8eca5cbbea360672aa29 Mon Sep 17 00:00:00 2001 From: Curve Date: Thu, 31 Oct 2024 19:01:23 +0100 Subject: [PATCH] docs(interop): mark `forget` as deprecated, mention `smartview::execute` --- docs/interoperability.mdx | 27 +++++++++++++++------------ src/components/CodeBlock.tsx | 2 +- 2 files changed, 16 insertions(+), 13 deletions(-) diff --git a/docs/interoperability.mdx b/docs/interoperability.mdx index e5acf5b..b756213 100644 --- a/docs/interoperability.mdx +++ b/docs/interoperability.mdx @@ -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("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("Math.pow({}, {})", 2, 5).get(); -smartview.evaluate("console.log({})", std::vector{10}).get(); +smartview.execute("console.log({})", std::vector{10}); ``` :::tip @@ -171,21 +171,24 @@ smartview.evaluate("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); +``` +::: + + Use `saucer::forget` in case you want to discard _(not use)_ the result of the evaluation. ```cpp title="Example Usage" saucer::forget(smartview.evaluate("Math.random()")); - smartview.evaluate("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(...)` should probably be forwarded to `saucer::forget` unless they originated from within an async context. -::: + ### All diff --git a/src/components/CodeBlock.tsx b/src/components/CodeBlock.tsx index da1dd32..b1587ca 100644 --- a/src/components/CodeBlock.tsx +++ b/src/components/CodeBlock.tsx @@ -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(() => {