Page Menu
Home
Phorge
Search
Configure Global Search
Log In
Files
F2921058
test_async_class_methods.cjs
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Size
1 KB
Referenced Files
None
Subscribers
None
test_async_class_methods.cjs
View Options
// Test async methods in classes
class AsyncTestClass {
constructor() {
this.name = 'AsyncTestClass';
this.value = 42;
}
// Regular method
regularMethod() {
console.log('regularMethod: this.name = ' + this.name);
return this.value;
}
// Async method
async asyncMethod() {
console.log('asyncMethod: this.name = ' + this.name);
return Promise.resolve(this.value * 2);
}
// Async method with argument
async asyncWithArg(multiplier) {
console.log('asyncWithArg: this.name = ' + this.name + ', multiplier = ' + multiplier);
return Promise.resolve(this.value * multiplier);
}
// Async method that calls helper
async asyncWithHelper() {
function helper() {
return 10;
}
console.log('asyncWithHelper: this.name = ' + this.name);
const extra = helper();
return Promise.resolve(this.value + extra);
}
}
const obj = new AsyncTestClass();
console.log('=== Test 1: Regular method ===');
const result1 = obj.regularMethod();
console.log('Result: ' + result1);
console.log('\n=== Test 2: Async method ===');
const promise2 = obj.asyncMethod();
console.log('Returned: ' + typeof promise2);
promise2.then(function (val) {
console.log('Resolved value: ' + val);
});
console.log('\n=== Test 3: Async method with argument ===');
const promise3 = obj.asyncWithArg(5);
console.log('Returned: ' + typeof promise3);
promise3.then(function (val) {
console.log('Resolved value: ' + val);
});
console.log('\n=== Test 4: Async method with helper function ===');
const promise4 = obj.asyncWithHelper();
console.log('Returned: ' + typeof promise4);
promise4.then(function (val) {
console.log('Resolved value: ' + val);
});
console.log('\n=== All tests completed ===');
File Metadata
Details
Attached
Mime Type
application/javascript
Expires
Fri, Mar 27, 7:58 AM (1 d, 22 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
512264
Default Alt Text
test_async_class_methods.cjs (1 KB)
Attached To
Mode
rANT Ant
Attached
Detach File
Event Timeline
Log In to Comment