// Enqueue kerneltry{ kernel_event =newcl.WebCLEvent();queue.enqueueNDRange(kernel,2,null, globals, locals,null,null, kernel_event);} catch(ex) {throw"Couldn't enqueue the kenrel. "+ ex;}// Set kernel event handling routines: call kernel_complete()try{kernel_event.setCallback(webcl.COMPLETE, kernel_complete,"The kernel finished successfully");} catch(ex){throw"Couldn't set callback for event. "+ ex;}// Read the buffervar data =newFloat32Array(4096);try{ read_event =newwebcl.WebCLEvent();queue.enqueueReadBuffer(clBuffer,false,0,4096*4, data,null, read_event);} catch(ex){throw"Couldn't read the buffer. "+ ex;}// register a callback on completion of read_event: calls read_complete()read_event.setCallback(webcl.COMPLETE, read_complete,"Read complete");// wait for both events to completequeue.waitForEvents([kernel_event, read_event]);// kernel callbackfunctionkernel_complete(event, data){// event.status = webcl.COMPLETE or error if negative// event.data is null// data should contain "The kernel finished successfully"}// read buffer callbackfunctionread_complete(event, data){// event.status = cl.COMPLETE or error if negative// event.data contains a WebCLMemoryObject with values from device// data contains "Read complete"}