mirror of
https://github.com/EvernodeXRPL/hpcore.git
synced 2026-04-29 15:37:59 +00:00
Contract execution refactor. (#153)
This commit is contained in:
@@ -21,13 +21,19 @@ const echoContract = (ctx) => {
|
||||
else {
|
||||
await user.send("Echoing: " + msg);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
// Broadcast message to all connected users.
|
||||
// ctx.users.get().forEach(u => u.send("Hello"));
|
||||
// Get list of all users who are connected.
|
||||
// ctx.users.get();
|
||||
|
||||
// Send message to specific user (identified by public key).
|
||||
// await ctx.users.find(<PubkeyHex>).send("Hello");
|
||||
// Get the user identified by public key.
|
||||
// ctx.users.find("<PubkeyHex>");
|
||||
|
||||
// Get list of all peers in the cluster.
|
||||
// ctx.peers.get();
|
||||
|
||||
// Get the peer identified by public key.
|
||||
// ctx.peers.find("<PubkeyHex>");
|
||||
|
||||
// Peer messages example.
|
||||
// if (!ctx.readonly) {
|
||||
|
||||
@@ -29,9 +29,9 @@ class HotPocketContract {
|
||||
const executionContext = new ContractExecutionContext(hpargs, users, peers);
|
||||
|
||||
this.events.emit("session_start");
|
||||
invokeCallback(contractFunc, executionContext).then(() => {
|
||||
invokeCallback(contractFunc, executionContext).catch(errHandler).finally(() => {
|
||||
// Wait for any pending tasks added during execution.
|
||||
Promise.all(pendingTasks).then(() => {
|
||||
Promise.all(pendingTasks).catch(errHandler).finally(() => {
|
||||
this.events.emit("session_end");
|
||||
this.#terminate();
|
||||
});
|
||||
@@ -121,7 +121,7 @@ class UsersCollection {
|
||||
if (pendingUserCount == 0) {
|
||||
// All user message events has been emitted.
|
||||
// Now start waiting for queued up user message callback completion.
|
||||
Promise.all(userMessageTasks).then(allUsersCompletionResolver)
|
||||
Promise.all(userMessageTasks).catch(errHandler).finally(allUsersCompletionResolver)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -368,13 +368,15 @@ const invokeCallback = async (callback, ...args) => {
|
||||
return;
|
||||
|
||||
if (callback.constructor.name === 'AsyncFunction') {
|
||||
await callback(...args);
|
||||
await callback(...args).catch(errHandler);
|
||||
}
|
||||
else {
|
||||
callback(...args);
|
||||
}
|
||||
}
|
||||
|
||||
const errHandler = (err) => console.log(err);
|
||||
|
||||
module.exports = {
|
||||
HotPocketContract
|
||||
}
|
||||
Reference in New Issue
Block a user