Melang

Logo

A script language of preemptive 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 in 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 message is a queue message, only one coroutine can get this message. If is topic message, every subscribed coroutine can receive this message.

mln_msg_topic_subscribe

Subscribe a topic message.

@mln_msg_topic_subscribe(qname);

Input:

Return value:

Error:

mln_msg_topic_unsubscribe

Unsubscribe a topic.

@mln_msg_topic_unsubscribe(qname);

Input:

Return value:

Error:

mln_msg_queue_send

Send message to a specified queue.

@mln_msg_queue_send(qname, msg, asTopic);

Input:

Return value:

Error:

mln_msg_queue_recv
@smln_msg_queue_recv(qname, timeout);

Input:

Return value:

Error:

Example
//file a.mln
@mln_msg_queue_send('test', 'hello');
//b.mln
msg = @mln_msg_queue_recv('test');
@mln_print(msg);
$ melang a.mln b.mln

The output is:

hello