From Kx Wiki
Jump to: navigation, search

The wiki is moving to a new format and this page is no longer maintained. You can find the new page at

The wiki will remain in place until the migration is complete. If you prefer the wiki to the new format, please tell the Librarian why.

AsQ: Flex/ActionScript Integration

AsQ library provides integration between q instance and ActionScript application. AsQ implements kdb+ ipc protocol and uses tcp sockets to communicate to q instance. AsQ does not rely on third party libraries and is self-contained.

[Bindable] public var q:c;
q=new c(host, p, user);
q.addEventListener(c.CONNECTED, _onKconnected);
q.addEventListener(c.DISCONNECTED, _onKdisconnected);
q.addEventListener(c.BEG_EXEC, _onBegExec);
q.addEventListener(c.END_EXEC, _onEndExec);
q.addEventListener(c.CONNECTION_ERROR, _onConnectionError);

ActionScript is the language behind the Flex technology. Flex applications run in Flash Player (FP) virtual machine (in browser or standalone). FP is an asynchronous environment where calls to external services do not block, but rather rely on callbacks (aka events). Therefore it is necessary to define the event listeners that will be called by the FP when server responds to user's actions.

AsQ implements following events

  • CONNECTED - connection to q established
  • DISCONNECTED - connection to q is closed
  • BEG_EXEC - request has been sent to q (can be used to provide visual feedback)
  • END_EXEC - response has been received from q (can be used to provide visual feedback)
  • CONNECTION_ERROR - connection was closed as a result of an error

Send code to q for execution and process the response:

q.ksync(cmd, this, "onKdata");

When response arrives from q, setter onKdata is called ('o' is q response deserialized into ActionScript native data structures):

public function set onKdata(o:Object):void {

Following is the full signature of ksync method:

public function ksync(
  timer:String=null):Boolean {

Flex application can call ksync() a number of times without waiting for response. AsQ will queue up the calls and execute them sequentially.

AsQ also contains source code for two sample Flex applications that use AsQ library: qui and taq. qui is a q terminal, that includes namespace browser (shows variables and functions defined in each directory), sends code to q for execution and lists q idioms (qui's main purpose is to serve as a learning tool). taq is trade and quote browser. It allows to drill into taq database down to tick level.

Q ActionScript
Dict Object
lambdas "func"
boolean Boolean
int, short, month, minute, second, time int
long, float, double, timespan Number
char, symbol String
timestamp, date, datetime Date
Personal tools