-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
266 additions
and
100 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,16 @@ | ||
import { blob, ic, heartbeat, query, Service } from 'azle'; | ||
import { managementCanister } from 'azle/canisters/management'; | ||
|
||
export default class extends Service { | ||
initialized: blob = Uint8Array.from([]); | ||
let initialized: blob = Uint8Array.from([]); | ||
|
||
@heartbeat | ||
async heartbeat() { | ||
export default Service({ | ||
heartbeat: heartbeat(async () => { | ||
const randomness = await ic.call(managementCanister.raw_rand); | ||
|
||
this.initialized = randomness; | ||
initialized = randomness; | ||
console.log('heartbeat initialized', randomness.length); | ||
} | ||
|
||
@query([], blob) | ||
getInitialized(): blob { | ||
return this.initialized; | ||
} | ||
} | ||
}), | ||
getInitialized: query([], blob, () => { | ||
return initialized; | ||
}) | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,13 @@ | ||
import { bool, heartbeat, query, Service } from 'azle'; | ||
|
||
export default class extends Service { | ||
initialized = false; | ||
let initialized = false; | ||
|
||
@heartbeat | ||
heartbeat() { | ||
this.initialized = true; | ||
console.log('heartbeat initialized', this.initialized); | ||
} | ||
|
||
@query([], bool) | ||
getInitialized(): bool { | ||
return this.initialized; | ||
} | ||
} | ||
export default Service({ | ||
heartbeat: heartbeat(() => { | ||
initialized = true; | ||
console.log('heartbeat initialized', initialized); | ||
}), | ||
getInitialized: query([], bool, () => { | ||
return initialized; | ||
}) | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import { isAsync } from '../../lib_new/method_decorators'; | ||
import { CanisterMethodInfo, executeMethod } from '.'; | ||
import { Void } from '../../lib_new'; | ||
|
||
export function heartbeat( | ||
callback: () => void | Promise<void> | ||
): CanisterMethodInfo<[], Void> { | ||
const finalCallback = (...args: any[]) => { | ||
executeMethod( | ||
'heartbeat', | ||
undefined, | ||
undefined, | ||
args, | ||
callback, | ||
[], | ||
Void, | ||
false | ||
); | ||
}; | ||
|
||
return { | ||
mode: 'heartbeat', | ||
callback: finalCallback, | ||
candid: '', | ||
candidTypes: [], | ||
paramsIdls: [], | ||
returnIdl: Void, | ||
async: isAsync(callback), | ||
guard: undefined | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters