-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathExampleAsyncEnabled.sol
28 lines (23 loc) · 1.03 KB
/
ExampleAsyncEnabled.sol
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.13;
import {RemoteExampleAsyncEnabled, myAsyncFunction1Promise} from "./interface/async/RemoteExampleAsyncEnabled.sol";
import {AsyncEnabled} from "../src/AsyncEnabled.sol";
// and assume that we want to create an async contract as follows:
contract ExampleAsyncEnabled is AsyncEnabled {
uint256 immutable valueToReturnAsync;
uint256 public lastValueReturned;
constructor(uint256 _valueToReturn) {
valueToReturnAsync = _valueToReturn;
}
function myAsyncFunction1() external async returns (uint256) {
return valueToReturnAsync;
}
function setValue(uint256 _value) external asyncCallback {
lastValueReturned = _value;
}
function makeAsyncCallAndStore(address _toAddress, uint256 _toChainId) external {
RemoteExampleAsyncEnabled remote = RemoteExampleAsyncEnabled(getAsyncProxy(_toAddress, _toChainId));
myAsyncFunction1Promise myPromise = remote.myAsyncFunction1();
myPromise.then(this.setValue);
}
}