Ticket #196: begin-end-invoke.patch
File begin-end-invoke.patch, 4.5 KB (added by hopscc, 15 years ago) |
---|
-
Source/Boxes.cobra
1489 1489 assert .parentBox or .parentNameSpace 1490 1490 1491 1491 def _bindInt 1492 m = Method(.token, .token, this, 'invoke', List<of Param>(.params), .returnType ? .returnTypeProxy, nil, List<of String>(.isNames), AttributeList(), '') 1493 m.statements.add(ThrowStmt(.token, PostCallExpr(.token, IdentifierExpr(.token, 'Exception'), List<of Expr>()))) # just to avoid a Cobra warning during .bindImp 1494 .addDecl(m) 1492 returnType as ITypeProxy = .returnType ? .returnTypeProxy 1493 .addDecl(_synthMethod('invoke', List<of Param>(.params), returnType)) 1494 vparam = Param('vParam', VariTypeIdentifier(.token, TypeIdentifier(.token, DynamicType()))) 1495 params = [vparam] # dynamic type vari length param in list as placeholder for multiple params 1496 .addDecl(_synthMethod('beginInvoke', params, TypeIdentifier(.token.copy('ID', 'IAsyncResult')) to ITypeProxy)) 1497 .addDecl(_synthMethod('endInvoke', params, returnType )) 1495 1498 base._bindInt 1496 1499 for param in .params 1497 1500 param.bindInt … … 1501 1504 def _makeInitializer is override 1502 1505 pass 1503 1506 1504 1507 def _synthMethod(name as String, params as List<of Param>?, returnTypeProxy as ITypeProxy) as Method 1508 m = Method(.token, .token, this, name, params, returnTypeProxy, nil, List<of String>(.isNames), AttributeList(), '') 1509 m.statements.add(ThrowStmt(.token, PostCallExpr(.token, IdentifierExpr(.token, 'Exception'), List<of Expr>()))) 1510 # method body just to avoid a Cobra warning during .bindImp 1511 return m 1512 1505 1513 class GenericParam inherits CobraType is partial 1506 1514 """ 1507 1515 A generic parameter *is* a type. -
Tests/220-delegates-etc/100-delegates/160-asyncThd.cobra
1 """ 2 Cobra xlation of sample fm http://msdn.microsoft.com/en-us/library/2e08f6yc.aspx 3 Test Ticket#196 - ability to compile when using {begin,end}Invoke 4 """ 5 use System.Threading 6 7 class AsyncDemo 8 #// The method to be executed asynchronously. 9 def testMethod(callDuration as int, threadId as out int ) as String 10 #Console.writeLine("Test method begins.") 11 Thread.sleep(callDuration) 12 threadId = Thread.currentThread.managedThreadId 13 return String.format("My call time was {0}.", callDuration.toString) to ! 14 15 #// The delegate must have the same signature as the method 16 #// it will call asynchronously. 17 #public delegate string AsyncMethodCaller(int callDuration, out int threadId); 18 sig AsyncMethodCaller(callDuration as int, threadId as out int) as String 19 20 21 class AsyncMain 22 def main is shared 23 24 # The asynchronous method puts the thread id here. 25 threadId as int 26 27 # Create an instance of the test class. 28 ad = AsyncDemo() 29 30 # Create the delegate. 31 caller as AsyncMethodCaller = AsyncMethodCaller(ref ad.testMethod) 32 33 # Initiate the asychronous call. 34 result = caller.beginInvoke(3000, out threadId, nil, nil) 35 #result as IAsyncResult = sharp'caller.BeginInvoke(3000, out threadId, null, null)' 36 37 Thread.sleep(0) 38 #Console.writeLine("Main thread {0} does some work.", Thread.currentThread.managedThreadId) 39 40 # Call EndInvoke to wait for the asynchronous call to complete, 41 # and to retrieve the results. 42 returnValue as String = caller.endInvoke(out threadId, result) 43 #returnValue as String = sharp'caller.EndInvoke(out threadId, result)' 44 45 assert threadId == 3 46 assert returnValue == 'My call time was 3000.' 47 #Console.writeLine('The call executed on thread {0}, with return value "{1}".', 48 # threadId, returnValue) 49 CobraCore.noOp(caller, result) # suppress warnings around params to sharp'{begin,end}Invoke' 50 51 52 -
Developer/IntermediateReleaseNotes.text
431 431 * Fixed: An uncaught exception can occur for some library calls. 432 432 433 433 * Fixed: Cannot instantiate generic params under some circumstances. 434 435 * Fixed: Cobra compile failure on delegates calling .{begin,end}Invoke. Ticket#196