feat: add Promise.all
This commit is contained in:
parent
eecfb6367f
commit
fee46c3710
@ -18,16 +18,25 @@ function hashCode(str: string): string {
|
|||||||
|
|
||||||
export const addWord = async (...[word]: AddWordArgs) => {
|
export const addWord = async (...[word]: AddWordArgs) => {
|
||||||
const id = hashCode(word);
|
const id = hashCode(word);
|
||||||
console.log('Before storeOp');
|
|
||||||
await storeOp(constructClaim(createWordKey(id), { word }, '0x0'));
|
await storeOp(constructClaim(createWordKey(id), { word }, '0x0'));
|
||||||
console.log('After storeOp');
|
|
||||||
|
|
||||||
const wordClaim = await readOp<TypedClaim<WordClaimBody>>(createWordKey(id));
|
const wordClaim = await readOp<TypedClaim<WordClaimBody>>(createWordKey(id));
|
||||||
console.log('After readOp');
|
|
||||||
const newWord = (wordClaim?.body.word ?? '') + '!!!';
|
|
||||||
const newId = hashCode(newWord);
|
|
||||||
|
|
||||||
console.log('Before 2 storeOp');
|
const newWord1 = (wordClaim?.body.word ?? '') + '!';
|
||||||
storeOp(constructClaim(createWordKey(newId), { word: newWord }, '0x0'));
|
const newId1 = hashCode(newWord1);
|
||||||
console.log('After 2 storeOp');
|
|
||||||
|
const newWord2 = (wordClaim?.body.word ?? '') + '!!';
|
||||||
|
const newId2 = hashCode(newWord2);
|
||||||
|
|
||||||
|
const newWord3 = (wordClaim?.body.word ?? '') + '!!!';
|
||||||
|
const newId3 = hashCode(newWord3);
|
||||||
|
|
||||||
|
await Promise.all([
|
||||||
|
storeOp(constructClaim(createWordKey(newId1), { word: newWord1 }, '0x0')),
|
||||||
|
storeOp(constructClaim(createWordKey(newId2), { word: newWord2 }, '0x0')),
|
||||||
|
storeOp(constructClaim(createWordKey(newId3), { word: newWord3 }, '0x0')),
|
||||||
|
]);
|
||||||
|
|
||||||
|
readOp<TypedClaim<WordClaimBody>>(createWordKey(newId3));
|
||||||
};
|
};
|
||||||
|
|||||||
@ -44,6 +44,12 @@ export const executor =
|
|||||||
method(...args).then(() => resolve(), reject);
|
method(...args).then(() => resolve(), reject);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
//@ts-expect-error
|
||||||
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-call
|
||||||
|
os.setTimeout(() => {
|
||||||
|
abortExecution?.();
|
||||||
|
}, 0);
|
||||||
|
|
||||||
await execution;
|
await execution;
|
||||||
|
|
||||||
const { authInfo, availableCweb } = getCallParameters(ctx);
|
const { authInfo, availableCweb } = getCallParameters(ctx);
|
||||||
@ -79,11 +85,3 @@ export const executor =
|
|||||||
),
|
),
|
||||||
];
|
];
|
||||||
};
|
};
|
||||||
|
|
||||||
export const abort = () => {
|
|
||||||
if (!abortExecution) {
|
|
||||||
throw new Error('Abort not found');
|
|
||||||
}
|
|
||||||
|
|
||||||
abortExecution();
|
|
||||||
};
|
|
||||||
|
|||||||
@ -2,7 +2,6 @@ import { Claim, ClaimKey, constructRead, extractRead, isResolvedRead } from '@co
|
|||||||
|
|
||||||
import { TypedClaim } from '../../types';
|
import { TypedClaim } from '../../types';
|
||||||
import { context } from '../context';
|
import { context } from '../context';
|
||||||
import { abort } from '../executor';
|
|
||||||
|
|
||||||
import { pushAwaitedOp } from './awaited';
|
import { pushAwaitedOp } from './awaited';
|
||||||
import { shiftResolvedOp } from './resolved';
|
import { shiftResolvedOp } from './resolved';
|
||||||
@ -14,7 +13,6 @@ export const readOp = <TClaim extends Claim = TypedClaim>(key: ClaimKey) => {
|
|||||||
|
|
||||||
if (!isOp) {
|
if (!isOp) {
|
||||||
pushAwaitedOp(constructRead(context.issuer, key));
|
pushAwaitedOp(constructRead(context.issuer, key));
|
||||||
abort();
|
|
||||||
} else {
|
} else {
|
||||||
if (op && !isResolvedRead(op)) {
|
if (op && !isResolvedRead(op)) {
|
||||||
throw new Error('Read operation not found');
|
throw new Error('Read operation not found');
|
||||||
|
|||||||
@ -1,8 +1,6 @@
|
|||||||
import { Claim, constructStore, isResolvedStore } from '@coinweb/contract-kit';
|
import { Claim, constructStore, isResolvedStore } from '@coinweb/contract-kit';
|
||||||
import { extractStore } from '@coinweb/contract-kit/dist/esm/operations/store';
|
import { extractStore } from '@coinweb/contract-kit/dist/esm/operations/store';
|
||||||
|
|
||||||
import { abort } from '../executor';
|
|
||||||
|
|
||||||
import { pushAwaitedOp } from './awaited';
|
import { pushAwaitedOp } from './awaited';
|
||||||
import { shiftResolvedOp } from './resolved';
|
import { shiftResolvedOp } from './resolved';
|
||||||
|
|
||||||
@ -13,7 +11,7 @@ export const storeOp = (claim: Claim) =>
|
|||||||
|
|
||||||
if (!isOp) {
|
if (!isOp) {
|
||||||
pushAwaitedOp(constructStore(claim));
|
pushAwaitedOp(constructStore(claim));
|
||||||
abort();
|
// abort();
|
||||||
} else {
|
} else {
|
||||||
if (op && !isResolvedStore(op)) {
|
if (op && !isResolvedStore(op)) {
|
||||||
throw new Error('Store operation not found');
|
throw new Error('Store operation not found');
|
||||||
|
|||||||
@ -1,7 +1,6 @@
|
|||||||
import { constructTake, extractTake, isResolvedTake, Claim, ClaimKey } from '@coinweb/contract-kit';
|
import { constructTake, extractTake, isResolvedTake, Claim, ClaimKey } from '@coinweb/contract-kit';
|
||||||
|
|
||||||
import { TypedClaim } from '../../types';
|
import { TypedClaim } from '../../types';
|
||||||
import { abort } from '../executor';
|
|
||||||
|
|
||||||
import { pushAwaitedOp } from './awaited';
|
import { pushAwaitedOp } from './awaited';
|
||||||
import { shiftResolvedOp } from './resolved';
|
import { shiftResolvedOp } from './resolved';
|
||||||
@ -13,7 +12,6 @@ export const takeOp = <TClaim extends Claim = TypedClaim>(key: ClaimKey) =>
|
|||||||
|
|
||||||
if (!isOp) {
|
if (!isOp) {
|
||||||
pushAwaitedOp(constructTake(key));
|
pushAwaitedOp(constructTake(key));
|
||||||
abort();
|
|
||||||
} else {
|
} else {
|
||||||
if (op && !isResolvedTake(op)) {
|
if (op && !isResolvedTake(op)) {
|
||||||
throw new Error('Take operation not found');
|
throw new Error('Take operation not found');
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
VITE_API_URL='https://api-cloud.coinweb.io/wallet'
|
VITE_API_URL='https://api-cloud.coinweb.io/wallet'
|
||||||
VITE_EXPLORER_URL='https://explorer.coinweb.io'
|
VITE_EXPLORER_URL='https://explorer.coinweb.io'
|
||||||
|
|
||||||
VITE_CONTRACT_ADDRESS="0xb5bd653b3e95ea8588b23d9fad48cd4cc6debd26ad9982d1249e116fad9100d5"
|
VITE_CONTRACT_ADDRESS="0xbaa19b2ee40d26f7d8bcececf9eeaaaed99fa5583527c80bd2c1c6de3753780c"
|
||||||
Loading…
x
Reference in New Issue
Block a user