Function promise_yield_resume

Source
pub fn promise_yield_resume(data_id: &CryptoHash, data: &[u8]) -> bool
Expand description

Accepts a resumption token data_id created by promise_yield_create on the local account. data is a payload to be passed to the callback method as a promise input. Returns false if no promise yield with the specified data_id is found. Returns true otherwise, guaranteeing that the callback method will be executed with a user-provided payload.

If promise_yield_resume is called multiple times with the same data_id, it is possible to get back multiple ‘true’ results. The payload from the first successful call is passed to the callback.

§Examples

use near_sdk::env::{promise_yield_create, promise_yield_resume, read_register};
use near_sdk::serde_json;
use near_sdk::{Gas, GasWeight, CryptoHash};

let DATA_ID_REGISTER = 0;
// Create yield promise
let promise = promise_yield_create(
    "increment",
    // passed as arguments
    serde_json::json!({
        "value": 5        
    }).to_string().into_bytes().as_slice(),
    Gas::from_tgas(10),
    GasWeight(0),
    DATA_ID_REGISTER
);

// Retrieve `data_id` for further resume
let data_id: CryptoHash = read_register(DATA_ID_REGISTER)
    .expect("read_register failed")
    .try_into()
    .expect("conversion to CryptoHash failed");

// Resume execution using previously retrieved `data_id`
promise_yield_resume(
    &data_id,
    // passed as callback_result
    serde_json::json!({
        "key": "value",
        "description": "some text"
    }).to_string().into_bytes().as_slice()
);

More low-level info here: near_vm_runner::logic::VMLogic::promise_yield_resume See example of usage here and here