# JavaWrapper

`com.jsmacrosce.jsmacros.graal.library.impl.FWrapper`

**Since:** 1.2.5

**Note:** re-named from `consumer` in 1.4.0

Wraps script callbacks for use as Java [MethodWrapper](../../../../../../../classes/com/jsmacrosce/jsmacros/core/MethodWrapper.md)s through the `JavaWrapper` library.  
 
 Graal contexts are entered by one thread at a time. Calls through these wrappers are coordinated
 by a priority queue; asynchronous wrappers schedule void callbacks on the script thread pool,  
 while calls that need a result run synchronously.

Accessible in scripts via the global `JavaWrapper` variable.

## Methods

### deferCurrentTask {#com.jsmacrosce.jsmacros.graal.library.impl.FWrapper_deferCurrentTask-}

```js
deferCurrentTask(): void
```

Yields the current script task while the supplied sleep operation runs, then rejoins the queue at its existing priority.

### deferCurrentTask {#com.jsmacrosce.jsmacros.graal.library.impl.FWrapper_deferCurrentTask-int-}

```js
deferCurrentTask(int priorityAdjust): void
```

Yields the current script task while the supplied sleep operation runs, then rejoins the queue with an adjusted priority.

**Parameters:**
- `priorityAdjust`: amount added to the current task priority

### getCurrentPriority {#com.jsmacrosce.jsmacros.graal.library.impl.FWrapper_getCurrentPriority-}

```js
getCurrentPriority(): int
```

**Returns:** the current script task's queue priority

### methodToJava {#com.jsmacrosce.jsmacros.graal.library.impl.FWrapper_methodToJava-Value-}

```js
methodToJava(Value c): MethodWrapper<A, B, R, GraalScriptContext>
```

Wraps a callable for Java use; each wrapper call executes the script function synchronously and returns its result.

**Parameters:**
- `c`: executable script function

**Type Parameters:**
- `A`: type of the first callback argument
- `B`: type of the second callback argument
- `R`: callback result type

**Returns:** wrapper that invokes `c` and returns its result

**Since:** 1.3.2

### methodToJavaAsync {#com.jsmacrosce.jsmacros.graal.library.impl.FWrapper_methodToJavaAsync-Value-}

```js
methodToJavaAsync(Value c): MethodWrapper<A, B, R, GraalScriptContext>
```

Wraps a callable for Java use. Calls that only need the callback to run, such as
 `accept` and `run`, are scheduled on the script thread pool and return
 immediately; their failures are logged. Calls that need a result, such as `apply`,  
 `test`, `get`, and `compare`, run synchronously on the caller and
 return or throw the result.  

 A scheduled callback joins the script queue from the pool worker that runs it, so two
 callbacks submitted by one script may start in either order. Priority decides which queued
 callback runs next; it does not make separate submissions start in submission order.

**Parameters:**
- `c`: executable script function

**Type Parameters:**
- `A`: type of the first callback argument
- `B`: type of the second callback argument
- `R`: callback result type

**Returns:** wrapper that schedules void callbacks and runs result-returning calls synchronously

**Since:** 1.3.2

### methodToJavaAsync {#com.jsmacrosce.jsmacros.graal.library.impl.FWrapper_methodToJavaAsync-int-Value-}

```js
methodToJavaAsync(int priority, Value c): MethodWrapper<A, B, R, ?>
```

Wraps a callable for asynchronous execution with an explicit queue priority. The other
 asynchronous overloads use priority 5. As with the no-priority form, only void callbacks
 are scheduled; calls that need a result run synchronously. Priority orders callbacks that
 are already queued; it does not order the submissions that put them there.

**Parameters:**
- `priority`: queue priority used to order callback execution
- `c`: executable script function

**Type Parameters:**
- `A`: type of the first callback argument
- `B`: type of the second callback argument
- `R`: callback result type

**Returns:** wrapper that schedules void callbacks, with their failures logged; result-returning calls run synchronously

### stop {#com.jsmacrosce.jsmacros.graal.library.impl.FWrapper_stop-}

```js
stop(): void
```

Closes the current script context, including its Graal context.

**Since:** 1.2.2
