Melang

Logo

A script language of time-sharing scheduling coroutine in single thread

View the Project on GitHub Water-Melon/Melang

Message Queue

This document introduces a set of functions about message queue. Message queue is only working on a coroutine group in the same thread.

There are two kinds of message: queue message and topic message.

Melang supports many coroutines to listen the same queue. If a message is a queue message, only one coroutine can obtain this message. If it is a topic message, every subscribed coroutine can obtain this message.

Import

mq = Import('mq');
subscribe

Subscribe a topic message.

mq.subscribe(qname);

Input:

Return value:

Error:

unsubscribe

Unsubscribe a topic.

mq.unsubscribe(qname);

Input:

Return value:

Error:

send

Send message to a specified queue.

mq.send(qname, msg, asTopic);

Input:

Return value:

Error:

recv
mq.recv(qname, timeout);

Input:

Return value:

Error:

Example
//file a.mln
mq = Import('mq');

mq.send('test', 'hello');
//b.mln
mq = Import('mq');
sys = Import('sys');

msg = mq.recv('test');
sys.print(msg);
$ melang a.mln b.mln

The output is:

hello