njs_promise_fulfill(njs_vm_t *vm, njs_promise_t *promise, njs_value_t *value)
{
    njs_queue_t         queue;
    njs_promise_data_t  *data;

    data = njs_data(&promise->value);

    data->result = *value;
    data->state = NJS_PROMISE_FULFILL;

    if (njs_queue_is_empty(&data->fulfill_queue)) {
        return njs_value_arg(&njs_value_undefined);

    } else {
        queue = data->fulfill_queue;

        queue.head.prev->next = &queue.head;
        queue.head.next->prev = &queue.head;
    }

    njs_queue_init(&data->fulfill_queue);
    njs_queue_init(&data->reject_queue);

    return njs_promise_trigger_reactions(vm, value, &queue);
}
njs_promise_fulfill(njs_vm_t *vm, njs_promise_t *promise, njs_value_t *value)
{
    njs_queue_t         queue;
    njs_promise_data_t  *data;

    data = njs_data(&promise->value);

    data->result = *value;
    data->state = NJS_PROMISE_FULFILL;

    if (njs_queue_is_empty(&data->fulfill_queue)) {
        return njs_value_arg(&njs_value_undefined);

    } else {
        queue = data->fulfill_queue;

        queue.head.prev->next = &queue.head;
        queue.head.next->prev = &queue.head;
    }

    njs_queue_init(&data->fulfill_queue);
    njs_queue_init(&data->reject_queue);

    return njs_promise_trigger_reactions(vm, value, &queue);
}